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

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Feb 26, 2024

What this does

When you do not provide enough args, you get an error telling you how many you need. It does not tell you what the arguments should be, so the user needs to run coder <cmd> --help to see.

Now we always print the FullUsage() when the number of arguments is incorrect for a cli command.

Before

$ coder exp example-error arg-required
Encountered an error running "coder exp example-error arg-required"
wanted 1 args but got 0 []

After

$ coder exp example-error arg-required
Encountered an error running "coder exp example-error arg-required"
Usage: coder exp example-error arg-required <required>
Error: wanted 1 args but got 0 []

@Emyrk Emyrk changed the title chore: add usage to # cli arg failures chore: provide usage instruction for CLI argument failures Feb 26, 2024
@Emyrk Emyrk requested a review from mafredri February 27, 2024 14:03
@@ -562,6 +562,16 @@ func Chain(ms ...MiddlewareFunc) MiddlewareFunc {
return chain(reversed...)
}

func UsageErrorPrefix(next HandlerFunc) HandlerFunc {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be a bit more descriptive as ShowUsageOnError or something like that? LGTM otherwise.

@Emyrk Emyrk force-pushed the stevenmasley/cli_errors branch from 6308a00 to 7fab067 Compare February 27, 2024 16:14
@Emyrk Emyrk force-pushed the stevenmasley/cli_errors branch from 7fab067 to 18fbeb7 Compare February 27, 2024 18:06
@Emyrk Emyrk merged commit 97f0838 into main Feb 28, 2024
@Emyrk Emyrk deleted the stevenmasley/cli_errors branch February 28, 2024 18:10
@github-actions github-actions bot locked and limited conversation to collaborators Feb 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants