From cecb5566f09548e985a4bb51ea88be7e935f10f6 Mon Sep 17 00:00:00 2001 From: huangmengxuan Date: Thu, 7 May 2026 15:38:50 +0800 Subject: [PATCH] fix: remove misleading default value from --as flag help text MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The --as flag displayed (default "bot"), (default "user"), or (default "auto") in help text, but ResolveAs() never uses the cobra default — it resolves identity via credential config and auto-detect. The displayed default misled users into thinking a fixed identity was used when --as was omitted. Set cobra default to empty string so no (default ...) suffix appears. Also remove "auto" from visible options since --as auto is equivalent to omitting --as entirely. Change-Id: I51ba550a6697eb3675a29f5cee4d0010e0a1cc16 --- cmd/root.go | 2 +- internal/cmdutil/identity_flag.go | 6 +++--- internal/cmdutil/identity_flag_test.go | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index a65e5f7373..34bf559b46 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -48,7 +48,7 @@ EXAMPLES: FLAGS: --params URL/query parameters JSON --data request body JSON (POST/PATCH/PUT/DELETE) - --as identity type: user | bot | auto (default: auto) + --as identity type: user | bot --format output format: json (default) | ndjson | table | csv | pretty --page-all automatically paginate through all pages --page-size page size (0 = use API default) diff --git a/internal/cmdutil/identity_flag.go b/internal/cmdutil/identity_flag.go index 1589120ea6..8dc320d453 100644 --- a/internal/cmdutil/identity_flag.go +++ b/internal/cmdutil/identity_flag.go @@ -14,8 +14,8 @@ import ( // AddAPIIdentityFlag registers the standard --as flag shape used by api/service commands. func AddAPIIdentityFlag(ctx context.Context, cmd *cobra.Command, f *Factory, target *string) { addIdentityFlag(ctx, cmd, f, target, identityFlagConfig{ - defaultValue: "auto", - usage: "identity type: user | bot | auto (default)", + defaultValue: "", + usage: "identity type: user | bot", completionValues: []string{"user", "bot"}, }) } @@ -26,7 +26,7 @@ func AddShortcutIdentityFlag(ctx context.Context, cmd *cobra.Command, f *Factory authTypes = []string{"user"} } addIdentityFlag(ctx, cmd, f, nil, identityFlagConfig{ - defaultValue: authTypes[0], + defaultValue: "", usage: "identity type: " + strings.Join(authTypes, " | "), completionValues: authTypes, }) diff --git a/internal/cmdutil/identity_flag_test.go b/internal/cmdutil/identity_flag_test.go index fa93d7263d..54d539583b 100644 --- a/internal/cmdutil/identity_flag_test.go +++ b/internal/cmdutil/identity_flag_test.go @@ -24,8 +24,8 @@ func TestAddAPIIdentityFlag_NonStrictMode(t *testing.T) { if flag.Hidden { t.Fatal("expected --as flag to be visible outside strict mode") } - if got := flag.DefValue; got != "auto" { - t.Fatalf("default value = %q, want %q", got, "auto") + if got := flag.DefValue; got != "" { + t.Fatalf("default value = %q, want empty string", got) } } @@ -49,7 +49,7 @@ func TestAddAPIIdentityFlag_StrictModeHidesFlagAndLocksDefault(t *testing.T) { } } -func TestAddShortcutIdentityFlag_UsesAuthTypes(t *testing.T) { +func TestAddShortcutIdentityFlag_NoDefault(t *testing.T) { f, _, _, _ := TestFactory(t, &core.CliConfig{AppID: "a", AppSecret: "s"}) cmd := &cobra.Command{Use: "test"} @@ -62,7 +62,7 @@ func TestAddShortcutIdentityFlag_UsesAuthTypes(t *testing.T) { if flag.Hidden { t.Fatal("expected --as flag to be visible outside strict mode") } - if got := flag.DefValue; got != "bot" { - t.Fatalf("default value = %q, want %q", got, "bot") + if got := flag.DefValue; got != "" { + t.Fatalf("default value = %q, want empty string", got) } }