Skip to content

Commit a0803a5

Browse files
authored
fix(cli): address 7 CLI consistency issues across help text and flag behavior (#25658)
1 parent e61c83d commit a0803a5

File tree

10 files changed

+28
-27
lines changed

10 files changed

+28
-27
lines changed

cmd/gh-aw/main.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,18 @@ By default, this command also removes orphaned include files that are no longer
174174
by any workflow. Use --keep-orphans to skip this cleanup.
175175
176176
Examples:
177-
` + string(constants.CLIExtensionPrefix) + ` remove my-workflow # Remove specific workflow
178-
` + string(constants.CLIExtensionPrefix) + ` remove test- # Remove all workflows starting with 'test-'
179-
` + string(constants.CLIExtensionPrefix) + ` remove old- --keep-orphans # Remove workflows but keep orphaned includes`,
177+
` + string(constants.CLIExtensionPrefix) + ` remove my-workflow # Remove specific workflow
178+
` + string(constants.CLIExtensionPrefix) + ` remove test- # Remove all workflows starting with 'test-'
179+
` + string(constants.CLIExtensionPrefix) + ` remove old- --keep-orphans # Remove workflows but keep orphaned includes
180+
` + string(constants.CLIExtensionPrefix) + ` remove my-workflow --dir .github/workflows/shared # Remove from custom directory`,
180181
RunE: func(cmd *cobra.Command, args []string) error {
181182
var pattern string
182183
if len(args) > 0 {
183184
pattern = args[0]
184185
}
185186
keepOrphans, _ := cmd.Flags().GetBool("keep-orphans")
186-
return cli.RemoveWorkflows(pattern, keepOrphans)
187+
workflowDir, _ := cmd.Flags().GetString("dir")
188+
return cli.RemoveWorkflows(pattern, keepOrphans, workflowDir)
187189
},
188190
}
189191

@@ -367,7 +369,6 @@ This command accepts one or more workflow IDs.
367369
The workflows must have been added as actions and compiled.
368370
369371
This command only works with workflows that have workflow_dispatch triggers.
370-
It executes 'gh workflow run <workflow-lock-file>' to trigger each workflow on GitHub Actions.
371372
372373
` + cli.WorkflowIDExplanation + `
373374
@@ -705,8 +706,10 @@ Use "` + string(constants.CLIExtensionPrefix) + ` help all" to show help for all
705706

706707
// Add flags to remove command
707708
removeCmd.Flags().Bool("keep-orphans", false, "Skip removal of orphaned include files that are no longer referenced by any workflow")
709+
removeCmd.Flags().StringP("dir", "d", "", "Workflow directory (default: .github/workflows)")
708710
// Register completions for remove command
709711
removeCmd.ValidArgsFunction = cli.CompleteWorkflowNames
712+
cli.RegisterDirFlagCompletion(removeCmd, "dir")
710713

711714
// Add flags to enable/disable commands
712715
enableCmd.Flags().StringP("repo", "r", "", "Target repository ([HOST/]owner/repo format). Defaults to current repository")

pkg/cli/add_command.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Examples:
6363
` + string(constants.CLIExtensionPrefix) + ` add githubnext/agentics/ci-doctor --create-pull-request --force
6464
` + string(constants.CLIExtensionPrefix) + ` add ./my-workflow.md # Add local workflow
6565
` + string(constants.CLIExtensionPrefix) + ` add ./*.md # Add all local workflows
66-
` + string(constants.CLIExtensionPrefix) + ` add githubnext/agentics/ci-doctor --dir shared # Add to .github/workflows/shared/
66+
` + string(constants.CLIExtensionPrefix) + ` add githubnext/agentics/ci-doctor --dir .github/workflows/shared # Add to .github/workflows/shared/
6767
6868
Workflow specifications:
6969
- Three parts: "owner/repo/workflow-name[@version]" (implicitly looks in workflows/ directory)
@@ -74,7 +74,7 @@ Workflow specifications:
7474
- Version can be tag, branch, or SHA (for remote workflows)
7575
7676
The -n flag allows you to specify a custom name for the workflow file (only applies to the first workflow when adding multiple).
77-
The --dir flag allows you to specify a subdirectory under .github/workflows/ where the workflow will be added.
77+
The --dir flag allows you to specify the workflow directory (default: .github/workflows).
7878
The --create-pull-request flag creates a pull request with the workflow changes.
7979
The --force flag overwrites existing workflow files.
8080
@@ -151,7 +151,7 @@ Note: For guided interactive setup, use the 'add-wizard' command instead.`,
151151
cmd.Flags().Bool("no-gitattributes", false, "Skip updating .gitattributes file")
152152

153153
// Add workflow directory flag to add command
154-
cmd.Flags().StringP("dir", "d", "", "Subdirectory under .github/workflows/ (e.g., 'shared' creates .github/workflows/shared/)")
154+
cmd.Flags().StringP("dir", "d", "", "Workflow directory (default: .github/workflows)")
155155

156156
// Add no-stop-after flag to add command
157157
cmd.Flags().Bool("no-stop-after", false, "Remove any stop-after field from the workflow")
@@ -328,11 +328,7 @@ func addWorkflowWithTracking(resolved *ResolvedWorkflow, tracker *FileTracker, o
328328
return fmt.Errorf("workflow directory must be a relative path, got: %s", opts.WorkflowDir)
329329
}
330330
opts.WorkflowDir = filepath.Clean(opts.WorkflowDir)
331-
if !strings.HasPrefix(opts.WorkflowDir, ".github/workflows") {
332-
githubWorkflowsDir = filepath.Join(gitRoot, ".github/workflows", opts.WorkflowDir)
333-
} else {
334-
githubWorkflowsDir = filepath.Join(gitRoot, opts.WorkflowDir)
335-
}
331+
githubWorkflowsDir = filepath.Join(gitRoot, opts.WorkflowDir)
336332
} else {
337333
githubWorkflowsDir = filepath.Join(gitRoot, ".github/workflows")
338334
}

pkg/cli/add_integration_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,8 @@ Test content.
432432
err = os.WriteFile(localWorkflowPath, []byte(localWorkflowContent), 0644)
433433
require.NoError(t, err, "should write local workflow file")
434434

435-
// Add to a custom directory
436-
cmd := exec.Command(setup.binaryPath, "add", localWorkflowPath, "--dir", "experimental")
435+
// Add to a custom directory (full path required, consistent with compile/fix/upgrade --dir)
436+
cmd := exec.Command(setup.binaryPath, "add", localWorkflowPath, "--dir", ".github/workflows/experimental")
437437
cmd.Dir = setup.tempDir
438438
output, err := cmd.CombinedOutput()
439439
outputStr := string(output)
@@ -442,7 +442,7 @@ Test content.
442442

443443
require.NoError(t, err, "add command should succeed: %s", outputStr)
444444

445-
// Verify the workflow file was created in the custom subdirectory
445+
// Verify the workflow file was created in the custom directory
446446
customDir := filepath.Join(setup.tempDir, ".github", "workflows", "experimental")
447447
info, err := os.Stat(customDir)
448448
require.NoError(t, err, "custom workflows subdirectory should exist")

pkg/cli/add_wizard_command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Note: To create a new workflow from scratch, use the 'new' command instead.`,
8484
cmd.Flags().Bool("no-gitattributes", false, "Skip updating .gitattributes file")
8585

8686
// Add workflow directory flag
87-
cmd.Flags().StringP("dir", "d", "", "Subdirectory under .github/workflows/ (e.g., 'shared' creates .github/workflows/shared/)")
87+
cmd.Flags().StringP("dir", "d", "", "Workflow directory (default: .github/workflows)")
8888

8989
// Add no-stop-after flag
9090
cmd.Flags().Bool("no-stop-after", false, "Remove any stop-after field from the workflow")

pkg/cli/commands_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ This is a test workflow to verify the --no-emit flag functionality.`
213213
}
214214

215215
func TestRemoveWorkflows(t *testing.T) {
216-
err := RemoveWorkflows("test-pattern", false)
216+
err := RemoveWorkflows("test-pattern", false, "")
217217

218218
// Should not error since it's a stub implementation
219219
if err != nil {
@@ -385,7 +385,7 @@ Test workflow for command existence.`
385385
_, err := CompileWorkflows(context.Background(), config)
386386
return err
387387
}, false, "CompileWorkflows"},
388-
{func() error { return RemoveWorkflows("nonexistent", false) }, false, "RemoveWorkflows"}, // Should handle missing directory gracefully
388+
{func() error { return RemoveWorkflows("nonexistent", false, "") }, false, "RemoveWorkflows"}, // Should handle missing directory gracefully
389389
{func() error { return StatusWorkflows("nonexistent", false, false, "", "", "") }, false, "StatusWorkflows"}, // Should handle missing directory gracefully
390390
{func() error {
391391
return RunWorkflowOnGitHub(context.Background(), "", RunOptions{})

pkg/cli/mcp_add.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ This command searches the MCP registry for the specified server, adds it to the
315315
and automatically compiles the workflow. If the tool already exists, the command will fail.
316316
317317
When called with no arguments, it will show a list of available MCP servers from the registry.
318-
When called with only a workflow argument, it will show an error asking for a server name.
319318
320319
The workflow-id-or-file can be:
321320
- A workflow ID (basename without .md extension, e.g., "weekly-research")

pkg/cli/pr_command.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ and creates a new pull request in the target repository with the same title and
7777
The target repository defaults to the current repository unless --repo is specified.
7878
7979
Examples:
80-
gh aw pr transfer https://github.com/trial/repo/pull/234
81-
gh aw pr transfer https://github.com/PR-OWNER/PR-REPO/pull/234 --repo owner/target-repo
80+
gh aw pr transfer https://github.com/owner/repo/pull/234
81+
gh aw pr transfer https://github.com/owner/repo/pull/234 --repo owner/target-repo
8282
8383
The command will:
8484
1. Fetch the PR details (title, body, changes)

pkg/cli/remove_command.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ import (
1717
var removeLog = logger.New("cli:remove_command")
1818

1919
// RemoveWorkflows removes workflows matching a pattern
20-
func RemoveWorkflows(pattern string, keepOrphans bool) error {
21-
removeLog.Printf("Removing workflows: pattern=%q, keepOrphans=%v", pattern, keepOrphans)
22-
workflowsDir := getWorkflowsDir()
20+
func RemoveWorkflows(pattern string, keepOrphans bool, workflowDir string) error {
21+
removeLog.Printf("Removing workflows: pattern=%q, keepOrphans=%v, workflowDir=%q", pattern, keepOrphans, workflowDir)
22+
workflowsDir := workflowDir
23+
if workflowsDir == "" {
24+
workflowsDir = getWorkflowsDir()
25+
}
2326

2427
if _, err := os.Stat(workflowsDir); os.IsNotExist(err) {
2528
fmt.Fprintln(os.Stderr, console.FormatInfoMessage("No .github/workflows directory found."))

pkg/cli/trial_command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func NewTrialCommand(validateEngine func(string) error) *cobra.Command {
1212
cmd := &cobra.Command{
1313
Use: "trial <workflow-spec>...",
1414
Short: "Run one or more agentic workflows in trial mode against a simulated repository",
15-
Long: `Trial one or more agentic workflows as if they were running in a repository.
15+
Long: `Run one or more agentic workflows in trial mode as if they were running in a repository.
1616
1717
This command creates a temporary private repository in your GitHub space, installs the specified
1818
workflow(s) from their source repositories, and runs them in "trial mode" to capture safe outputs without

pkg/cli/upgrade_command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Examples:
109109
}
110110

111111
cmd.Flags().StringP("dir", "d", "", "Workflow directory (default: .github/workflows)")
112-
cmd.Flags().Bool("no-fix", false, "Only update agent files (skips codemods, action version updates, and workflow compilation)")
112+
cmd.Flags().Bool("no-fix", false, "Skip codemods, action version updates, and workflow compilation (only update agent files)")
113113
cmd.Flags().Bool("no-actions", false, "Skip updating GitHub Actions versions")
114114
cmd.Flags().Bool("no-compile", false, "Skip recompiling workflows (do not modify lock files)")
115115
cmd.Flags().Bool("create-pull-request", false, "Create a pull request with the upgrade changes")

0 commit comments

Comments
 (0)