Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions internal/cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}, "<feature>"},
} {
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) {
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/flag_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ func runFlagToggle(cmd *cobra.Command, name string, enable bool) error {
// environment).
var flagCreateCmd = &cobra.Command{
Use: "create <feature>",
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 {
Expand All @@ -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)
},
}

Expand Down
Loading