From 871d90846fc38b116fc1dff75bbe5e2b262d1f54 Mon Sep 17 00:00:00 2001 From: David Caldwell Date: Mon, 24 Sep 2018 23:21:11 +0000 Subject: [PATCH] Add a more helpful error message when unkown options are encountered --- docopt.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docopt.go b/docopt.go index c22feb7..a670cd3 100644 --- a/docopt.go +++ b/docopt.go @@ -181,7 +181,15 @@ func parse(doc string, argv []string, help bool, version string, optionsFirst bo return } - err = newUserError("") + if len(*left) > 0 { + var left_names []string + for _, l := range(*left) { + left_names = append(left_names, l.name) + } + err = newUserError(fmt.Sprintf("Unknown option(s): %s", strings.Join(left_names, ", "))) + } else { + err = newUserError("") + } output = handleError(err, usage) return }