Skip to content

refactor(cmd): replace os.Exit/log.Fatalf with RunE and add Args validators#344

Closed
Harishrs2006 wants to merge 1 commit intomicrocks:masterfrom
Harishrs2006:refactor/issue-281-cobra-args-prune-validate
Closed

refactor(cmd): replace os.Exit/log.Fatalf with RunE and add Args validators#344
Harishrs2006 wants to merge 1 commit intomicrocks:masterfrom
Harishrs2006:refactor/issue-281-cobra-args-prune-validate

Conversation

@Harishrs2006
Copy link
Copy Markdown

  1. add SilenceErrors: true to root command to prevent errors being printed twice by both Cobra and main().
  2. import, import-url, import-dir: cobra.ExactArgs(1) replaces manual len(args) guard and os.Exit; RunE returns wrapped errors.
  3. test: cobra.ExactArgs(3) replaces direct os.Args inspection; PreRunE validates --waitFor format and runner type before any network call; extract parseWaitForMilliseconds helper for testability
  4. start, stop: RunE replaces log.Fatalf with fmt.Errorf
  5. all subcommands now return errors instead of calling os.Exit — errors propagate cleanly to main().

Fixes #281

…dators

Migrate all subcommands from Run to RunE and remove process-termination
patterns so errors propagate cleanly through Cobra to main():

- cmd.go: add SilenceErrors so errors are not double-printed
- import, import-url, import-dir: ExactArgs(1) replaces manual len(args)
  guard + os.Exit; RunE returns wrapped errors
- test: ExactArgs(3) replaces direct os.Args inspection; PreRunE validates
  --waitFor format and runner type before network calls; RunE returns errors
- start, stop: RunE replaces log.Fatalf with fmt.Errorf
- Extract parseWaitForMilliseconds helper for testability

Fixes microcks#281

Signed-off-by: Harish R S <harishrs21082006@gmail.com>
@Harishrs2006
Copy link
Copy Markdown
Author

Closing in favour of #280 which covers the same refactor more completely
(also adds login/logout/context validation and --port range checks).
Didn't see #280 existed when I opened this — sorry for the duplicate.

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.

CLI Commands use os.Exit/log.Fatalf instead of cobra's RunE, Args, and PreRun

1 participant