Skip to content

Commit

Permalink
stub the init command
Browse files Browse the repository at this point in the history
Signed-off-by: catsby <clint@defenseunicorns.com>
  • Loading branch information
catsby committed Jan 17, 2025
1 parent b769946 commit b52b177
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/cmd/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ var genCLIDocs = &cobra.Command{
rootCmd.RemoveCommand(scanCmd)
rootCmd.RemoveCommand(planCmd)
rootCmd.RemoveCommand(applyCmd)
rootCmd.RemoveCommand(initCmd)

// Set the default value for the uds-cache flag (otherwise this defaults to the user's home directory)
rootCmd.Flag("uds-cache").DefValue = "~/.uds-cache"
Expand Down
4 changes: 3 additions & 1 deletion src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ func init() {
rootCmd.PersistentFlags().BoolVar(&config.NoColor, "no-color", v.GetBool(V_NO_COLOR), lang.RootCmdFlagNoColor)

// Add a persistent flag for setting features
rootCmd.PersistentFlags().StringVar(&cliFeatures, "feature", "", "Comma-separated list of features to enable (e.g., 'tofu')")
rootCmd.PersistentFlags().StringVar(&cliFeatures, "feature", "", "Comma-separated list of features to enable via a flag")
// hide the 'feature' flag for now
_ = rootCmd.PersistentFlags().MarkHidden("feature")

rootCmd.AddCommand(monitor.Cmd)
}
Expand Down
1 change: 1 addition & 0 deletions src/cmd/uds.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var createCmd = &cobra.Command{
if err != nil {
return fmt.Errorf("error reading the current working directory")
}

if len(args) > 0 {
srcDir = args[0]
}
Expand Down
19 changes: 18 additions & 1 deletion src/cmd/vendored.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,23 @@ var scanCmd = &cobra.Command{
DisableFlagParsing: true,
}

// uds init [bundle-name] will initialize tofu in the current directory. If a
// bundle name is provided, it will use the bundle as the source for the Tofu
// providers and uds-bundle.tf file.
var initCmd = &cobra.Command{
Use: "init [BUNDLE_TARBALL]",
Short: lang.CmdBundleApplyShort,
Args: cobra.MaximumNArgs(0),
RunE: func(_ *cobra.Command, _ []string) error {
if !featureflags.IsEnabled("tofu") {
fmt.Println("The 'init' command is not enabled. Use the '--feature=tofu' flag or set the FEATURE_FLAG environment variable.")
return nil
}
return useEmbeddedTofu()
},
DisableFlagParsing: true,
}

func init() {
// grab Zarf version to make Zarf library checks happy
if buildInfo, ok := debug.ReadBuildInfo(); ok {
Expand All @@ -177,5 +194,5 @@ func init() {
rootCmd.AddCommand(scanCmd) // uds-security-hub CLI command
rootCmd.AddCommand(planCmd) // tofu plan
rootCmd.AddCommand(applyCmd) // tofu apply

rootCmd.AddCommand(initCmd) // tofu init
}
1 change: 1 addition & 0 deletions src/config/lang/lang.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const (

// bundle apply
CmdBundleApplyShort = "Create or update infrastructure with Tofu"
CmdBundleInitShort = "Initialize OpenTofu"

// bundle inspect
CmdBundleInspectShort = "Display the metadata of a bundle"
Expand Down

0 comments on commit b52b177

Please # to comment.