-
Notifications
You must be signed in to change notification settings - Fork 431
Align CLI help/grouping and flag semantics for command consistency #41727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
52825fc
ea47cad
ac818a4
b54a217
e52d7a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| //go:build !integration | ||
|
|
||
| package main | ||
|
|
||
| import "testing" | ||
|
|
||
| func TestCompileCommandShortFlags(t *testing.T) { | ||
| forceFlag := compileCmd.Flags().Lookup("force") | ||
| if forceFlag == nil { | ||
| t.Fatal("expected --force flag on compile command") | ||
| } | ||
| if forceFlag.Shorthand != "f" { | ||
| t.Fatalf("expected --force shorthand to be -f, got -%s", forceFlag.Shorthand) | ||
| } | ||
|
|
||
| logicalRepoFlag := compileCmd.Flags().Lookup("logical-repo") | ||
| if logicalRepoFlag == nil { | ||
| t.Fatal("expected --logical-repo flag on compile command") | ||
| } | ||
| if logicalRepoFlag.Shorthand != "l" { | ||
| t.Fatalf("expected --logical-repo shorthand to be -l, got -%s", logicalRepoFlag.Shorthand) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ func addEngineFlag(cmd *cobra.Command) { | |
| // addEngineFilterFlag adds the --engine/-e flag to a command for filtering. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/improve-codebase-architecture] Stale comment: 💡 Suggested fixChange line 17 from: // addEngineFilterFlag adds the --engine/-e flag to a command for filtering.to: // addEngineFilterFlag adds the --engine flag (no shorthand) to a command for filtering.The intent to distinguish filter-only from override-style flags is clear in the implementation — the comment just needs to match. |
||
| // This flag allows filtering results by AI engine type. | ||
|
|
||
| func addEngineFilterFlag(cmd *cobra.Command) { | ||
| cmd.Flags().StringP("engine", "e", "", engineFlagUsage("Filter logs by AI engine")) | ||
| cmd.Flags().String("engine", "", engineFlagUsage("Filter logs by AI engine")) | ||
| } | ||
|
|
||
| // addRepoFlag adds the --repo/-r flag to a command. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,6 +59,14 @@ func TestShortFlagConsistency(t *testing.T) { | |
| shouldExist: true, | ||
| description: "update should have force short flag", | ||
| }, | ||
| { | ||
| name: "compile command has -f for --force", | ||
| shortFlag: "f", | ||
| longFlag: "force", | ||
| commandSetup: func() *cobra.Command { return createCompileCommandStub() }, | ||
| shouldExist: true, | ||
| description: "compile should have force short flag", | ||
| }, | ||
|
|
||
| // -F flag (raw-field in run command) | ||
| { | ||
|
|
@@ -147,6 +155,14 @@ func TestShortFlagConsistency(t *testing.T) { | |
| shouldExist: true, | ||
| description: "update should have dir short flag", | ||
| }, | ||
| { | ||
| name: "compile command has -l for --logical-repo", | ||
| shortFlag: "l", | ||
| longFlag: "logical-repo", | ||
| commandSetup: func() *cobra.Command { return createCompileCommandStub() }, | ||
| shouldExist: true, | ||
| description: "compile should have logical-repo short flag", | ||
| }, | ||
|
|
||
| // -c flag (count) - should only be in logs command | ||
| { | ||
|
|
@@ -175,6 +191,14 @@ func TestShortFlagConsistency(t *testing.T) { | |
| shouldExist: true, | ||
| description: "disable should have repo short flag", | ||
| }, | ||
| { | ||
| name: "logs command does not have -e for --engine", | ||
| shortFlag: "e", | ||
| longFlag: "engine", | ||
| commandSetup: func() *cobra.Command { return NewLogsCommand() }, | ||
| shouldExist: false, | ||
| description: "logs should not have engine short flag", | ||
| }, | ||
|
|
||
| // -w flag (watch) | ||
| { | ||
|
|
@@ -233,8 +257,10 @@ func TestShortFlagConsistency(t *testing.T) { | |
| func createCompileCommandStub() *cobra.Command { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/zoom-out] 💡 ConsiderationThe stub exists because // createCompileCommandStub mirrors the shorthand flags defined on compileCmd
// in cmd/gh-aw/main.go. Keep this in sync when adding new shorthands.
// The authoritative test for the real command is cmd/gh-aw/compile_flags_test.go.
func createCompileCommandStub() *cobra.Command { |
||
| cmd := &cobra.Command{Use: "compile"} | ||
| cmd.Flags().StringP("engine", "e", "", "Override AI engine") | ||
| cmd.Flags().BoolP("force", "f", false, "Force overwrite") | ||
| cmd.Flags().BoolP("watch", "w", false, "Watch for changes") | ||
| cmd.Flags().StringP("dir", "d", "", "Workflow directory") | ||
| cmd.Flags().StringP("logical-repo", "l", "", "Repository to simulate") | ||
| cmd.Flags().BoolP("json", "j", false, "Output results in JSON format") | ||
| return cmd | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,7 @@ func NewLogsCommand() *cobra.Command { | |
|
|
||
| logsCmd := &cobra.Command{ | ||
| Use: "logs [workflow]", | ||
| Short: "Download and analyze agentic workflow logs with aggregated metrics", | ||
| Short: "Download and analyze agentic workflow logs and artifacts", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/grill-with-docs] The new short description If |
||
| Long: fmt.Sprintf(`Download and analyze agentic workflow logs and artifacts from GitHub Actions. | ||
|
|
||
| This command fetches workflow runs, downloads their artifacts, and extracts them into | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing the real
compileCmdglobal duplicates assertions already inflags_test.goand couples tests to shared init state.The new entries in
flags_test.goalready verify--force/-fand--logical-repo/-lviacreateCompileCommandStub(). This file then re-tests the same properties against the package-globalcompileCmd— two different mechanisms asserting the same invariant means two files that must be updated together on every shorthand change.💡 Details
The two-layer approach (stub for pattern consistency + real command for registration correctness) is reasonable in principle, but the implementation has a subtle risk:
compileCmdis shared mutable global state initialized byinit(). Any test inpackage mainthat registers or removes a flag oncompileCmd(even in at.Cleanup) would silently corrupt this test's expectations.A safer approach is to extract command construction into a factory function:
That lets both this test and the stub test use an isolated instance with no shared-state risk. Non-blocking, but worth addressing before the pattern spreads to other command tests.