nodeca / argparse

CLI arguments parser for node.js. JS port of python's argparse module.
Other
491 stars 73 forks source link

Provide an option to bring back correct sentence capitalization #175

Open octogonz opened 1 year ago

octogonz commented 1 year ago

Migrating from version 1.0 to version 2.0, we noticed that this library has switched to starting descriptions with a lower case letter. For example -h now says show this help message and exit:

$ ./test.js -h
usage: test.js [-h] [-v] [-f FOO] [-b BAR] [--baz BAZ]

Argparse example

optional arguments:
  -h, --help         show this help message and exit
  -v, --version      show program's version number and exit
  -f FOO, --foo FOO  foo bar
  -b BAR, --bar BAR  bar foo
  --baz BAZ          baz bar

I understand that this is part of the efforts to more closely mimic the Python implementation of argparse. 👍

And indeed, Python uses short lower case sentence fragments for its own docs:

usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Options and arguments (and corresponding environment variables):
-b     : issue warnings about comparing bytearray with unicode
         (-bb: issue errors)
-B     : don't write .py[co] files on import; also PYTHONDONTWRITEBYTECODE=x
-c cmd : program passed in as string (terminates option list)
-d     : debug output from parser; also PYTHONDEBUG=x
-E     : ignore PYTHON* environment variables (such as PYTHONPATH)
-h     : print this help message and exit (also --help)
-i     : inspect interactively after running script; forces a prompt even
         if stdin does not appear to be a terminal; also PYTHONINSPECT=x
. . .

HOWEVER, many many many other tools prefer to write more detailed documentation using grammatically complete English sentences. Some popular examples:

Even Python's own package manager uses properly capitalized full sentences:

Usage:
  pip <command> [options]
  . . .
General Options:
  -h, --help                  Show help.
  --debug                     Let unhandled exceptions propagate outside the main subroutine,
                              instead of logging them to stderr.
  --isolated                  Run pip in an isolated mode, ignoring environment variables and user
                              configuration.
  --require-virtualenv        Allow pip to only run in a virtual environment; exit with an error
                              otherwise.

Feature request

To support tools that want to adopt maintstream capitalization, it would be great if this library provided a setting to capitalize the first letter of sentences, and generally to provide less terse phrasing of messages.

Or alternatively, maybe the API could provide a general way to customize all of the strings printed by the library, and then we can adjust them however we like. (This might also provide a simple mechanism for localization.)

Ruanrls commented 1 year ago

I've created a pull request for that: https://github.com/nodeca/argparse/pull/176

@octogonz #176

rlidwka commented 1 year ago

You can override the entire help action like this:

const argparse = require('argparse')
const parser = new argparse.ArgumentParser({ add_help: false })

parser.add_argument(
  '-h',
  '--help',
  {
    action: 'help',
    default: argparse.SUPPRESS,
    help: 'Show this help message and exit.'
  }
)

parser.print_help()

Please also check bugreport in python version: https://bugs.python.org/issue45912

Any solution they have over there should work here as well.

puzrin commented 1 year ago

https://github.com/python/cpython/issues/90070 at first glance, a similar issue in python mainstream recommends to customize help formatter.

Did you try to find python solution? The same principle should work here too. It would be not nice to diverge code from upstream.

https://stackoverflow.com/questions/35847084/customize-argparse-help-message