From b52b17728a2f74465b852b4e264c2b8e78745ac8 Mon Sep 17 00:00:00 2001 From: catsby Date: Fri, 17 Jan 2025 16:55:46 -0600 Subject: [PATCH] stub the init command Signed-off-by: catsby --- src/cmd/internal.go | 1 + src/cmd/root.go | 4 +++- src/cmd/uds.go | 1 + src/cmd/vendored.go | 19 ++++++++++++++++++- src/config/lang/lang.go | 1 + 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/cmd/internal.go b/src/cmd/internal.go index 2799fbbf..c208ccbb 100644 --- a/src/cmd/internal.go +++ b/src/cmd/internal.go @@ -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" diff --git a/src/cmd/root.go b/src/cmd/root.go index b511f529..4e61df85 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -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) } diff --git a/src/cmd/uds.go b/src/cmd/uds.go index be0ad386..0f72160e 100644 --- a/src/cmd/uds.go +++ b/src/cmd/uds.go @@ -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] } diff --git a/src/cmd/vendored.go b/src/cmd/vendored.go index 342f9777..d138dc9c 100644 --- a/src/cmd/vendored.go +++ b/src/cmd/vendored.go @@ -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 { @@ -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 } diff --git a/src/config/lang/lang.go b/src/config/lang/lang.go index 63c1b7a9..c3e1fbc9 100644 --- a/src/config/lang/lang.go +++ b/src/config/lang/lang.go @@ -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"