Skip to content

Commit

Permalink
feat: Implemented the basic functionality of tfbox.
Browse files Browse the repository at this point in the history
  • Loading branch information
vahid-haghighat committed Jan 14, 2025
1 parent f7212d1 commit ba8c529
Show file tree
Hide file tree
Showing 12 changed files with 899 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
3 changes: 2 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version: 2
before:
hooks:
- ./scripts/update_version.sh
- go mod tidy
- go generate ./...
builds:
Expand Down Expand Up @@ -31,7 +32,7 @@ brews:
homepage: "https://github.com/vahid-haghighat/tfbox"
description: "Another terraform version selector, combined with docker"
license: "MIT"
test: system "#{bin}/tfbox --version"
test: system "#{bin}/tfbox version"
install: bin.install "tfbox"
repository:
owner: brewdex
Expand Down
42 changes: 42 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package cmd

import (
"fmt"
"github.com/spf13/cobra"
"github.com/vahid-haghighat/tfbox/internal"
"os"
)

var workingDirectory string
var tfVersion string
var rootDirectory string

var rootCmd = &cobra.Command{
Use: "tfbox",
Short: "Runs terraform inside docker",
Long: `"Runs terraform inside docker"`,
RunE: func(cmd *cobra.Command, args []string) error {
tfArgs := cmd.Flags().Args()

if len(tfArgs) == 0 {
return fmt.Errorf("you need to pass terraform commands/flags")
}
return internal.Run(rootDirectory, workingDirectory, tfVersion, tfArgs)
},
Args: func(cmd *cobra.Command, args []string) error {
return nil
},
}

func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}

func init() {
rootCmd.Flags().StringVarP(&rootDirectory, "root", "r", "", "The root of the project")
rootCmd.Flags().StringVarP(&workingDirectory, "directory", "d", ".", "Terraform working directory relative to root directory")
rootCmd.Flags().StringVarP(&tfVersion, "version", "v", "", "Terraform version to use")
}
22 changes: 22 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cmd

import (
"fmt"
"github.com/vahid-haghighat/tfbox/version"

"github.com/spf13/cobra"
)

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "tfbox version",
Long: `tfbox version`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(version.Version)
},
}

func init() {
rootCmd.AddCommand(versionCmd)
}
55 changes: 55 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
module github.com/vahid-haghighat/tfbox

go 1.23.4

require (
github.com/PuerkitoBio/goquery v1.10.1
github.com/docker/docker v27.4.1+incompatible
github.com/hashicorp/go-version v1.7.0
github.com/hashicorp/hc-install v0.9.1
github.com/hashicorp/terraform-config-inspect v0.0.0-20241129133400-c404f8227ea6
github.com/spf13/cobra v1.8.1
)

require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/agext/levenshtein v1.2.2 // indirect
github.com/andybalholm/cascadia v1.3.3 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f // indirect
github.com/hashicorp/hcl/v2 v2.20.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/term v0.5.2 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/zclconf/go-cty v1.14.4 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0 // indirect
go.opentelemetry.io/otel v1.33.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.33.0 // indirect
go.opentelemetry.io/otel/metric v1.33.0 // indirect
go.opentelemetry.io/otel/sdk v1.33.0 // indirect
go.opentelemetry.io/otel/trace v1.33.0 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.9.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
gotest.tools/v3 v3.5.1 // indirect
)
210 changes: 210 additions & 0 deletions go.sum

Large diffs are not rendered by default.

Loading

0 comments on commit ba8c529

Please sign in to comment.