Skip to content

refactor: adopt idiomatic cobra patterns across all commands#279

Closed
mynk8 wants to merge 3 commits intomicrocks:masterfrom
mynk8:refactor-cobra-idiomatic
Closed

refactor: adopt idiomatic cobra patterns across all commands#279
mynk8 wants to merge 3 commits intomicrocks:masterfrom
mynk8:refactor-cobra-idiomatic

Conversation

@mynk8
Copy link
Copy Markdown

@mynk8 mynk8 commented May 4, 2026

No description provided.

mynk8 added 3 commits May 2, 2026 20:58
Replace Run with RunE, manual len(args) checks with cobra.Args validators,
and os.Exit(1) calls with error returns across all 11 command files.

The original cobra migration (PR microcks#125) directly translated the old
flag/command.Execute() pattern into cobra's Run, preserving os.Exit(1)
for error handling. This meant cobra's PreRunE, Args, and RunE hooks
were never adopted, and deferred calls were skipped on errors.

Changes:
- All commands: Run -> RunE returning error
- test: Args ExactArgs(3), PreRunE for runner validation
- import: Args MinimumNArgs(1)
- import-url: Args MinimumNArgs(1)
- import-dir: Args ExactArgs(1)
- login: Args ExactArgs(1), PreRunE for --sso-port range validation
- logout: Args ExactArgs(1)
- context: conditional arg validation in RunE
- start: PreRunE for --port range validation
- Root command: add SilenceErrors alongside existing SilenceUsage
- 24 os.Exit(1) calls removed, replaced by error returns
- log.Fatalf calls in start/stop replaced by fmt.Errorf returns
- Port validation tests for --port and --sso-port
@mynk8 mynk8 requested review from Harsh4902, lbroudoux and yada as code owners May 4, 2026 15:50
@mynk8 mynk8 closed this May 4, 2026
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.

1 participant