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

Provide an option to bring back correct sentence capitalization #175

Open
octogonz opened this issue Oct 23, 2023 · 3 comments
Open

Provide an option to bring back correct sentence capitalization #175

octogonz opened this issue Oct 23, 2023 · 3 comments

Comments

@octogonz
Copy link

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:

  • tsc: --help, -h Print this message.
  • gcc: -help Display available options
  • eslint: -h, --help Show help
  • powershell: -Help, -?, /? Shows this message.
  • webpack: -h, --help [verbose] Display help for commands and options.

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
Copy link

Ruanrls commented Nov 9, 2023

I've created a pull request for that: #176

@octogonz #176

@rlidwka
Copy link
Member

rlidwka commented Nov 18, 2023

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
Copy link
Member

puzrin commented Nov 18, 2023

python/cpython#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

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

No branches or pull requests

4 participants