feat(cli): show root help on bare invocation#9
Merged
Conversation
Running `gskill` with no arguments now prints the root help screen to stdout and exits 0, identical to `gskill --help` and `gskill -h`, instead of printing the version. This also fixes a latent bug where `gskill --help` printed help but exited 2. Drop the `default:"1"` tag from the version command, rewrite an empty argument list to `--help`, and capture Kong's Exit callback so a help request resolves to exit code 0 before the parse-error branch. Invalid flags and unknown commands still exit non-zero, and `gskill version` still prints the version.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the CLI’s default behavior so that invoking gskill with no arguments prints the root help text to stdout and exits 0, matching gskill --help / gskill -h. It also fixes the prior latent bug where --help exited with code 2.
Changes:
- Removed the
versioncommand’s default selection so “no args” is no longer implicitlyversion. - Rewrites a truly bare invocation (
len(args)==0) to--helpto ensure byte-identical help output across all help entrypoints. - Updates tests to assert help output/exit code behavior (including byte-identical output) and to keep unknown-command behavior non-zero.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| internal/cli/root.go | Routes bare invocation through Kong’s --help path and treats help as success (exit 0), removing the default version command selection. |
| internal/cli/root_test.go | Replaces the old “bare runs version” test with coverage for bare/--help/-h help output, exit codes, and unknown-command non-zero behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Make a bare
gskillinvocation print the root help screen to stdout and exit0, identical togskill --helpandgskill -h. Previouslygskillprinted the version, andgskill --helpprinted help but exited 2 (a latent bug, now fixed). Invalid input and failing commands still exit non-zero.Spec lives under
specs/005-cli-default-help/(kept untracked per project convention).Changes
internal/cli/root.go: dropdefault:"1"from theversioncommand; rewrite an empty arg list to--help; capture Kong'sExitcallback intohelpRequestedand returnCodeOK(0) before the parse-error branch. Routing the bare case through Kong's own--helpflag makes the three help outputs byte-identical for free.internal/cli/root_test.go: replace the obsoleteTestRun_BareInvocationRunsDefaultVersion(which pinned the old bare->version default) with tests for bare/--help/-h-> help + exit 0, byte-identical output, commands+flags listed, and unknown-command -> non-zero.Behavior
gskill0gskill --help/-h0gskill version0gskill <unknown>/--badflag2Verification
root.gochange, passing after../scripts/verify.shexits0— fmt, vet, golangci-lint,-racetests, coverage floor, govulncheck (0 vulns), gitleaks (0 leaks).docs/reference/commands.md) unchanged.