Skip to content

Updating console.error messages suggesting to clients run --help command #766

@GeorgeGkas

Description

@GeorgeGkas

I post a possible enchantment.

Description

One of the core features of commander.js is the ability to show meaningful error messages to the user. The API provides .on('--help', cb) listener on commands that allow users to add custom help messages (a description, examples, etc). However, to be able someone gets those help information he needs to provide --help argument in the command. For instance, if we have the following command node index.js rm <file> we are able to provide an .on('--help', cb) listener to command('rm <file>').

When new clients want to use our CLI tool will find themselves, most of the time, struggling to figure out how to use a command. For instance, if they forget the <file> argument in rm they'll face the following error message:

error: missing required argument `file'

Our client now needs to go to our API documentation and search what the <file> argument is (a path or name?). For simple commands, such as the above example, this isn't something interesting, but in more sophisticated commands, this actually can add headaches. Of course, the client can always add --help argument to that command and get the appropriate information. But most of the times, he will miss it.

Proposal Fix

I propose to update those error messages by adding one more line that will suggest our client try the --help argument. As such, the above message will be changed to:

error: missing required argument `file'
Try '--help' for more information.

This is something that most UNIX like commands do (check rm, cp, mv, etc) and I believe that increases the User Experience. Of course, we can propose other alternatives as well: Print the whole help page below the error message, but in my opinion, this is something that would add more noise.

A fix like this will not add any break changes to the codebase nor will decrease the test coverage.

If you agree with this idea, I will immediately open a new pull request.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions