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

Better error message about missing arguments for subcommands #39

Closed
freehck opened this issue Dec 3, 2015 · 9 comments
Closed

Better error message about missing arguments for subcommands #39

freehck opened this issue Dec 3, 2015 · 9 comments

Comments

@freehck
Copy link

freehck commented Dec 3, 2015

% bf2 buildpkg       
bf2: required argument PLATFORM is missing
Usage: bf2 buildpkg [OPTION]... PKGNAME VERSION PLATFORM

Obviously it should be reported about the missing argument PKGNAME.

I suppose the problem is in intertal command matching. Cmdliner sees that the 3rd parameter of command is missed. And reported that there's not the 3rd parameter of subcommand in the error message.

The code to reproduce it:

let buildpkg_cmd =
  let doc = "..." in
  let man = help_secs in

  let pkgname =
    Arg.(required & pos 0 (some string) None & info [] ~docv:"PKGNAME") in
  let version =
    Arg.(required & pos 1 (some string) None & info [] ~docv:"VERSION") in
  let platform =
    Arg.(required & pos 2 (some string) None & info [] ~docv:"PLATFORM") in

  Term.(...),
  Term.info "buildpkg" ~doc ~man

and eventually:

let () = match Term.eval_choice default_cmd [buildpkg_cmd] with
  | `Error _ -> exit 1
  | _ -> exit 0
@dbuenzli
Copy link
Owner

dbuenzli commented Dec 3, 2015

Obviously it should be reported about the missing argument PKGNAME.

Well obviously the PLATFORM parameter is also missing so this is not a wrong error message... but yes maybe I could start to report from the left. Which error is reported if you respectively specify one, and two positional arguments ?

@dbuenzli
Copy link
Owner

dbuenzli commented Dec 3, 2015

Also a fully reproducible test case would be nice.

@dbuenzli
Copy link
Owner

dbuenzli commented Dec 3, 2015

I think from a user point of view we should simply report all missing required arguments, not stop at the first one.

@hcarty
Copy link

hcarty commented Dec 3, 2015

Agreed, I'd prefer a report of all missing required arguments if that's reasonable.

If only one is reported then the first missing would be nice to have.

@freehck
Copy link
Author

freehck commented Dec 4, 2015

I'll supply you with reproducible examples after holidays, okay? I'm a little bit busy now.
Well, I'd prefer an error message either with only first missed parameter because I can easily determine the set of missed parameters from the 2nd line with "Usage" string.

@dbuenzli
Copy link
Owner

dbuenzli commented Dec 5, 2015

Well, I'd prefer an error message either with only first missed parameter because I can easily determine the set of missed parameters from the 2nd line with "Usage" string.

I'd say that the usage line only allows you to see at which position the missing arguments are due.

If the error message only tells you "required argument PKGNAME is missing" your brain will likely focus to fill in PKGNAME, failing to realize other required arguments are missing. In other words it's a misleading error message that will likely bring you to a new erroring interaction.

If the error is "required arguments PKGNAME, VERSION and PLATFORM are missing", you'll be more likely to take care to try to fill in all the arguments and the usage line will help you figure out at which position the arguments are due.

@dbuenzli dbuenzli changed the title Wrong error message about missing arguments for subcommands Better error message about missing arguments for subcommands Jan 27, 2017
@dbuenzli
Copy link
Owner

dbuenzli commented Feb 2, 2017

In fact the problem is even worse: the actual argument that is reported depends on the way you construct your term.

dbuenzli added a commit that referenced this issue Feb 2, 2017
dbuenzli added a commit that referenced this issue Feb 2, 2017
@dbuenzli
Copy link
Owner

dbuenzli commented Feb 2, 2017

This should be fixed, all missing required arguments should be reported, in order. Thanks for the report.

@dbuenzli dbuenzli reopened this Feb 3, 2017
@dbuenzli
Copy link
Owner

dbuenzli commented Feb 3, 2017

This introduced the regression that we can no longer as for --help if the tool has required arguments and they are not provided. We should test if help is requested before raising the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants