Skip to content
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

feat: Add the WithUsage function. #2097

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

feat: Add the WithUsage function. #2097

wants to merge 2 commits into from

Conversation

octo
Copy link

@octo octo commented Jan 12, 2024

Add a wrapper for PositionalArgs that supplements errors with usage information.

The error messages provided by the PositionalArgs functions is quite terse, e.g.

accepts n arg(s), received m

In many cases this will not be enough information for users to correct their mistake. The new WithUsage function includes the usage string in the error message to improve the user experience.

Example:

cmd := &cobra.Command{
	Use:  "example <arg>",
	Args: cobra.WithUsage(cobra.ExactArgs(1)),
}

@CLAassistant
Copy link

CLAassistant commented Jan 12, 2024

CLA assistant check
All committers have signed the CLA.

@marckhouzam
Copy link
Collaborator

I like this.
And I like the use of an example function in the tests, which we haven’t done before.
Nice job.

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.

None yet

3 participants