Skip to content

chore: provide usage instruction for CLI argument failures #12309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
UsageErrorPrefix -> ShowUsageOnError
  • Loading branch information
Emyrk committed Feb 27, 2024
commit 18fbeb7d54928bb6f0da52243ea0ae279baf66ad
6 changes: 3 additions & 3 deletions cli/clibase/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ func Chain(ms ...MiddlewareFunc) MiddlewareFunc {
return chain(reversed...)
}

func UsageErrorPrefix(next HandlerFunc) HandlerFunc {
func ShowUsageOnError(next HandlerFunc) HandlerFunc {
return func(i *Invocation) error {
err := next(i)
if err != nil {
Expand All @@ -584,8 +584,8 @@ func RequireRangeArgs(start, end int) MiddlewareFunc {
panic("start must be >= 0")
}
return func(next HandlerFunc) HandlerFunc {
// UsageErrorPrefix will add the command usage before the error message.
return UsageErrorPrefix(func(i *Invocation) error {
// ShowUsageOnError will add the command usage before the error message.
return ShowUsageOnError(func(i *Invocation) error {
got := len(i.Args)
switch {
case start == end && got != start:
Expand Down