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

Add a more helpful error message when unkown options are encountered #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

caldwell
Copy link

When there is a bad option, docopt-go silently prints the usage and gives no indication of which option(s) it didn't like. It's very confusing when a program with a lot of options has a command line with one of them misspelled.

This patch complains about unknown options instead of silently printing the usage.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.08%) to 88.344% when pulling 871d908 on caldwell:unknown-option-err into ee0de3b on docopt:master.

@artburkart
Copy link

artburkart commented Jul 16, 2019

I just ran into this, so now my go.mod looks like this:

module github.com/username/project-name

require (
    github.com/caldwell/docopt.go v0.0.0-20180924233533-871d90846fc3
)

and my go file looks like this:

package main
import (
	docopt "github.com/caldwell/docopt.go"
)

for _, l := range(*left) {
left_names = append(left_names, l.name)
}
err = newUserError(fmt.Sprintf("Unknown option(s): %s", strings.Join(left_names, ", ")))

Choose a reason for hiding this comment

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

@caldwell - I believe golint will complain about this error message because the first letter is capitalized.
https://github.com/golang/go/wiki/CodeReviewComments#error-strings

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.

3 participants