felixSchl/neodoc

Unnecessary blank lines in "Unknown option" error

moll opened this issue · 6 comments

moll commented

Hey,

I modeled my usage text according to GNU conventions:

Usage: foo [options] [<file>]

Options:
    -h, --help     Display this help and exit.
    -V, --version  Display version and exit.

Calling Neodoc.run with it and passing an invalid option on the CLI, you'll get back an extraneous blank line (2 in total):

Usage: foo [options] [<file>]


Unknown option: -x

I take it's because of the blank line after Usage:.
I'd go with either zero, one or follow GNU utils or Git that print the error above the Usage line:

% ls --asdf
ls: unrecognized option '--asdf'
Try 'ls --help' for more information.
% git --asdf
Unknown option: --asdf
usage: git [--version] [--help] [-C <path>] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

Cheers

moll commented

Printing the app name before the error, like ls does, is useful for identifying which command failed in pipelines.

I think I cannot do Try 'ls --help' for more information. until #48 is taken care of, but I do like it. It would be great to have this configurable by user. I am going to consider the double lines a bug and fix that straight away and consider the improved help output an enhancement that needs a bit more planning - for example if we did make it configurable, how would this configuration look like? So far I tried to keep configuration simple, most things being just flags you can toggle because I was thinking I could do sth with template strings later and have a set of flags like regular expressions do.

@moll Do you think the program name should be an option or derived from the usage section? Or both, where configuration would take precedence? That leads into something else, I think this should be an "incoherent specification" error:

usage: foo
   or: bar

because the program name is said to be "foo" and "bar". What do you think?

with the lastest commit to feature/deriving-program-name, the output is as follows:

> node examples/git -sdf
git: unknown option: -sdf
usage: git [--version] [--help] [-C <path>] [-c <name=value>]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           [<command> [<args>]...]

It's not configurable yet, however. I wonder if it even needs to be now.

This has been merged as of 005c826 and addresses all of the issues raised in the OP. If we want to make this configurable, we should track this in a new issue.

@moll you can try the new behaviour now at https://felixschl.github.io/neodoc (it's running a preview version of v0.8.0. feedback would be much appreciated)