diff --git a/internal/cmd/cmd_test.go b/internal/cmd/cmd_test.go index 1777c36..8e6b338 100644 --- a/internal/cmd/cmd_test.go +++ b/internal/cmd/cmd_test.go @@ -8272,20 +8272,36 @@ func TestAPI(t *testing.T) { } func TestFlagCreateIsNudge(t *testing.T) { - // Given / When - f := flagUpdateEnv(t) - out, err := run("", "flag", "create", "brand-new") + for _, tc := range []struct { + name string + args []string + want string + }{ + {"with a feature name", []string{"flag", "create", "brand-new"}, "brand-new"}, + {"without a feature name", []string{"flag", "create"}, ""}, + } { + t.Run(tc.name, func(t *testing.T) { + // Given + flagUpdateEnv(t) - // Then - var ue *usageError - if !errors.As(err, &ue) || !strings.Contains(hintFor(err), "feature create brand-new") { - t.Errorf("err = %v (hint %q), want a hint nudging toward `feature create`", err, hintFor(err)) - } - // ...but no usage block: `flag create` is a hidden redirect, not a real command. - if strings.Contains(out, "Usage:") { - t.Errorf("hidden redirect should not print a usage block:\n%s", out) + // When + out, err := run("", tc.args...) + + // Then + var ue *usageError + if !errors.As(err, &ue) { + t.Fatalf("err = %v, want a usage error", err) + } + for _, want := range []string{"flags can only be changed, not created", "flagsmith feature create " + tc.want, "flagsmith flag update " + tc.want + " --enable"} { + if !strings.Contains(out, want) { + t.Errorf("output = %q, want %q", out, want) + } + } + if strings.Contains(out, "Usage:") { + t.Errorf("hidden redirect should not print a usage block:\n%s", out) + } + }) } - _ = f } func TestAuthStatusHonoursConfigAPIURL(t *testing.T) { diff --git a/internal/cmd/flag_update.go b/internal/cmd/flag_update.go index 4d20258..9c5696b 100644 --- a/internal/cmd/flag_update.go +++ b/internal/cmd/flag_update.go @@ -462,7 +462,7 @@ func runFlagToggle(cmd *cobra.Command, name string, enable bool) error { // environment). var flagCreateCmd = &cobra.Command{ Use: "create ", - Short: "Not applicable — flags exist per environment (see `feature create`)", + Short: "Use feature create or flag update", Hidden: true, Args: cobra.ArbitraryArgs, RunE: func(cmd *cobra.Command, args []string) error { @@ -471,8 +471,8 @@ var flagCreateCmd = &cobra.Command{ name = args[0] } return hintf( - usageErrorf("flags exist per environment, so there is nothing to create"), - "To create the feature itself, run `flagsmith feature create %s`.", name) + usageErrorf("flags can only be changed, not created"), + "To create a feature, run `flagsmith feature create %s`.\nTo enable an existing flag, run `flagsmith flag update %s --enable`.", name, name) }, }