Skip to content

Complete Run→RunE migration for all remaining commands (Batch 5/5)#5378

Merged
pelikhan merged 3 commits intomainfrom
copilot/migrate-remaining-commands-to-rune
Dec 3, 2025
Merged

Complete Run→RunE migration for all remaining commands (Batch 5/5)#5378
pelikhan merged 3 commits intomainfrom
copilot/migrate-remaining-commands-to-rune

Conversation

Copy link
Contributor

Copilot AI commented Dec 3, 2025

Completes the Run→RunE migration by converting the final 12 commands across pkg/cli/ and cmd/gh-aw/main.go. All 107+ commands in the codebase now use RunE for proper error propagation through Cobra.

Changes

Command Migrations

  • pkg/cli/init_command.go - InitCommand
  • pkg/cli/add_command.go - AddCommand
  • pkg/cli/update_command.go - UpdateCommand
  • pkg/cli/mcp_server.go - MCPServerCommand
  • cmd/gh-aw/main.go - rootCmd, newCmd, removeCmd, enableCmd, disableCmd, compileCmd, versionCmd, customHelpCmd

Error Handling

  • Added rootCmd.SilenceErrors = true to centralize error formatting in main()
  • Removed fmt.Fprintln(os.Stderr, console.FormatErrorMessage(...)) + os.Exit(1) patterns
  • Commands now return errors directly: return err instead of printing and exiting

Test Updates

  • Fixed TestCommandErrorHandling to check error return values instead of stderr output
  • Updated TestCompletionDirectiveNoFileComp to accommodate Cobra completion output format
  • Removed unused imports from affected test files

Example

Before:

Run: func(cmd *cobra.Command, args []string) {
    if err := validateEngine(engineOverride); err != nil {
        fmt.Fprintln(os.Stderr, console.FormatErrorMessage(err.Error()))
        os.Exit(1)
    }
    if err := UpdateWorkflows(...); err != nil {
        fmt.Fprintln(os.Stderr, console.FormatErrorMessage(err.Error()))
        os.Exit(1)
    }
},

After:

RunE: func(cmd *cobra.Command, args []string) error {
    if err := validateEngine(engineOverride); err != nil {
        return err
    }
    return UpdateWorkflows(...)
},

The main() function now handles all error formatting consistently:

if err := rootCmd.Execute(); err != nil {
    fmt.Fprintln(os.Stderr, console.FormatErrorMessage(err.Error()))
    os.Exit(1)
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/user
    • Triggering command: /usr/bin/gh gh api user --jq .login (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[plan] Migrate remaining commands to RunE and verify complete migration</issue_title>
<issue_description>## Objective

Complete the Run→RunE migration by updating all remaining commands and verifying the entire codebase is migrated.

Context

This is Batch 5 of 5 in the Run→RunE migration. This ensures 100% coverage and validates the complete migration.

Parent Issue: #5300
Depends on: Batches 1-4 should be completed first

Approach

1. Identify Remaining Commands

Scan the entire pkg/cli/ directory for any commands still using Run::

grep -r "Run: func" pkg/cli/
grep -r "os.Exit(1)" pkg/cli/

2. Migrate Each Remaining Command

Apply the standard migration pattern:

  • Change Run: to RunE:
  • Remove os.Exit(1) calls
  • Return errors directly

3. Verification

After migration, verify no Run: usage remains:

# Should return no results
grep -r "^\s*Run:\s*func" pkg/cli/
grep -r "os.Exit(1)" pkg/cli/

4. Update Documentation

If any documentation mentions the old error handling pattern, update it to reference the new approach.

Files to Modify

  • Any remaining command files in pkg/cli/ not covered in batches 1-4
  • Potentially update documentation in DEVGUIDE.md or similar files

Acceptance Criteria

  • Zero commands use Run: (all use RunE:)
  • Zero os.Exit(1) calls in command functions
  • All commands return errors to Cobra
  • Complete test suite passes (make test)
  • Linting passes (make lint)
  • Manual smoke testing of all commands succeeds
  • Documentation updated if needed
  • Verification grep commands return no results

Verification Commands

# Build fresh binary
make clean
make build

# Verify no old patterns remain
grep -r "Run: func" pkg/cli/ cmd/
grep -r "os.Exit(1)" pkg/cli/ cmd/

# Full test suite
make test
make lint

# Smoke test major commands
./gh-aw --help
./gh-aw compile --help
./gh-aw status
./gh-aw logs --help

Final Checklist

AI generated by Plan Command for #5282

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits December 3, 2025 08:26
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Migrate remaining commands to RunE and verify migration Complete Run→RunE migration for all remaining commands (Batch 5/5) Dec 3, 2025
Copilot AI requested a review from pelikhan December 3, 2025 08:52
@pelikhan pelikhan marked this pull request as ready for review December 3, 2025 14:06
@pelikhan pelikhan merged commit 9487dbe into main Dec 3, 2025
4 checks passed
@pelikhan pelikhan deleted the copilot/migrate-remaining-commands-to-rune branch December 3, 2025 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[plan] Migrate remaining commands to RunE and verify complete migration

2 participants