From b7699465ac0fd2cec38f131786a87ceb5c275add Mon Sep 17 00:00:00 2001 From: catsby Date: Thu, 16 Jan 2025 16:46:42 -0600 Subject: [PATCH] add feature flag gate to apply/plan stubs Signed-off-by: catsby --- src/cmd/root.go | 17 ----------------- src/cmd/vendored.go | 11 ++++++++++- src/config/lang/lang.go | 5 +---- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/cmd/root.go b/src/cmd/root.go index cff14adb..b511f529 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -128,8 +128,6 @@ func init() { rootCmd.PersistentFlags().StringVar(&cliFeatures, "feature", "", "Comma-separated list of features to enable (e.g., 'tofu')") rootCmd.AddCommand(monitor.Cmd) - // apply cmd - rootCmd.AddCommand(applyCmd) } // loadViperConfig reads the config file and unmarshals the relevant config into DeployOpts.Variables @@ -180,18 +178,3 @@ func unmarshalAndValidateConfig(configFile []byte, bundleCfg *types.BundleConfig } return nil } - -var applyCmd = &cobra.Command{ - Use: "apply", - Short: lang.CmdBundleApplyShort, - Args: cobra.MaximumNArgs(0), - RunE: func(_ *cobra.Command, _ []string) error { - if !featureflags.IsEnabled("tofu") { - fmt.Println("The 'apply' command is not enabled. Use the '--feature=tofu' flag or set the FEATURE_FLAG environment variable.") - return nil - } - fmt.Println("Executing 'apply' command...") - return nil - }, - DisableFlagParsing: true, -} diff --git a/src/cmd/vendored.go b/src/cmd/vendored.go index db8136a2..342f9777 100644 --- a/src/cmd/vendored.go +++ b/src/cmd/vendored.go @@ -21,6 +21,7 @@ import ( "github.com/defenseunicorns/uds-cli/src/config" "github.com/defenseunicorns/uds-cli/src/config/lang" + "github.com/defenseunicorns/uds-cli/src/pkg/featureflags" "github.com/spf13/cobra" zarfCLI "github.com/zarf-dev/zarf/src/cmd" zarfConfig "github.com/zarf-dev/zarf/src/config" @@ -119,6 +120,10 @@ var planCmd = &cobra.Command{ Short: lang.CmdBundlePlanShort, // Args: cobra.MaximumNArgs(0), RunE: func(_ *cobra.Command, args []string) error { + if !featureflags.IsEnabled("tofu") { + fmt.Println("The 'plan' command is not enabled. Use the '--feature=tofu' flag or set the FEATURE_FLAG environment variable.") + return nil + } return useEmbeddedTofu() }, DisableFlagParsing: true, @@ -128,7 +133,11 @@ var applyCmd = &cobra.Command{ Use: "apply", Short: lang.CmdBundleApplyShort, Args: cobra.MaximumNArgs(0), - RunE: func(_ *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { + if !featureflags.IsEnabled("tofu") { + fmt.Println("The 'apply' command is not enabled. Use the '--feature=tofu' flag or set the FEATURE_FLAG environment variable.") + return nil + } return useEmbeddedTofu() }, DisableFlagParsing: true, diff --git a/src/config/lang/lang.go b/src/config/lang/lang.go index f625940f..63c1b7a9 100644 --- a/src/config/lang/lang.go +++ b/src/config/lang/lang.go @@ -55,7 +55,7 @@ const ( //TODO: @JPERRY come up with better strings for here.. CmdBundlePlanShort = "Generate a Tofu execution plan" - // bundle plan + // bundle apply CmdBundleApplyShort = "Create or update infrastructure with Tofu" // bundle inspect @@ -66,9 +66,6 @@ const ( CmdBundleInspectFlagFindImages = "Derive images from a uds-bundle.yaml file and list them" CmdBundleInspectFlagListVariables = "List all configurable variables in a bundle (including zarf variables)" - // bundle apply - CmdBundleApplyShort = "Create or update infrastructure with Tofu" - // bundle remove CmdBundleRemoveShort = "Remove a bundle that has been deployed already" CmdBundleRemoveFlagConfirm = "REQUIRED. Confirm the removal action to prevent accidental deletions"