-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
gh-90300: split --help output into separate options #30331
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
Changes from 6 commits
225c869
eaefd1a
57fd33b
55dbf69
0aaf9af
a592003
1c4cf63
d8bfcff
38f2dd8
a828fe8
8bde4ec
0dbaf03
0c9a995
aab464f
064d4ad
b9a0b19
0ee24d4
dd2beaa
c74fc69
2f108fe
4f345e8
a6573d6
da97a38
98525b4
5585095
24526bd
0bb5dfa
8fa72f5
29d04a0
356d1bf
ac1b5fb
9bcea95
5485255
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Make ``--help`` output shorter by moving some info to the new | ||
``--help-env`` and ``-X help`` options. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,10 +66,10 @@ python \- an interpreted, interactive, object-oriented programming language | |
.B \-x | ||
] | ||
[ | ||
[ | ||
.B \-X | ||
.I option | ||
] | ||
[ | ||
merwok marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.B \-? | ||
] | ||
.br | ||
|
@@ -81,6 +81,16 @@ python \- an interpreted, interactive, object-oriented programming language | |
| | ||
.I never | ||
] | ||
.br | ||
[ | ||
.B \--help | ||
] | ||
[ | ||
.B \--help-env | ||
] | ||
[ | ||
.B \-X help | ||
] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought showing all help options on their own line could be nice. |
||
.br | ||
[ | ||
.B \-c | ||
|
@@ -146,6 +156,9 @@ the behavior of the interpreter. | |
.B \-h ", " \-? ", "\-\-help | ||
Prints the usage for the interpreter executable and exits. | ||
.TP | ||
.B \-\-help\-env | ||
Prints help about environment variables and exits. | ||
.TP | ||
.B \-i | ||
When a script is passed as first argument or the \fB\-c\fP option is | ||
used, enter interactive mode after executing the script or the | ||
|
@@ -279,7 +292,9 @@ a regular expression on the warning message. | |
|
||
.TP | ||
.BI "\-X " option | ||
Set implementation specific option. The following options are available: | ||
Set implementation-specific option. The following options are available: | ||
|
||
-X help: show help about available options | ||
|
||
-X faulthandler: enable faulthandler | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,8 +63,20 @@ static const char usage_3[] = "\ | |
-W arg : warning control; arg is action:message:category:module:lineno\n\ | ||
also PYTHONWARNINGS=arg\n\ | ||
-x : skip first line of source, allowing use of non-Unix forms of #!cmd\n\ | ||
-X opt : set implementation-specific option. The following options are available:\n\ | ||
\n\ | ||
-X opt : set implementation-specific option (see details with -X help)\n\ | ||
--help-env : print help about other environment variables\n\ | ||
merwok marked this conversation as resolved.
Show resolved
Hide resolved
merwok marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--check-hash-based-pycs always|default|never :\n\ | ||
control how Python invalidates hash-based .pyc files\n\ | ||
"; | ||
static const char usage_4[] = "\ | ||
file : program read from script file\n\ | ||
- : program read from stdin (default; interactive mode if a tty)\n\ | ||
arg ...: arguments passed to program in sys.argv[1:]\n\ | ||
"; | ||
|
||
static const char usage_xoptions[] = "\ | ||
merwok marked this conversation as resolved.
Show resolved
Hide resolved
|
||
The following implementation-specific options are available:\n\ | ||
-X help: show this help\n\ | ||
merwok marked this conversation as resolved.
Show resolved
Hide resolved
|
||
-X faulthandler: enable faulthandler\n\ | ||
-X showrefcount: output the total reference count and number of used\n\ | ||
memory blocks when the program finishes or after each statement in the\n\ | ||
|
@@ -99,28 +111,22 @@ static const char usage_3[] = "\ | |
when the interpreter displays tracebacks.\n\ | ||
-X frozen_modules=[on|off]: whether or not frozen modules should be used.\n\ | ||
The default is \"on\" (or \"off\" if you are running a local build).\n\ | ||
\n\ | ||
--check-hash-based-pycs always|default|never:\n\ | ||
control how Python invalidates hash-based .pyc files\n\ | ||
"; | ||
static const char usage_4[] = "\ | ||
file : program read from script file\n\ | ||
- : program read from stdin (default; interactive mode if a tty)\n\ | ||
arg ...: arguments passed to program in sys.argv[1:]\n\n\ | ||
Other environment variables:\n\ | ||
static const char usage_envvars1[] = "\ | ||
Environment variables that change behavior (see also --help):\n\ | ||
PYTHONSTARTUP: file executed on interactive startup (no default)\n\ | ||
PYTHONPATH : '%lc'-separated list of directories prefixed to the\n\ | ||
default module search path. The result is sys.path.\n\ | ||
"; | ||
static const char usage_5[] = | ||
static const char usage_envvars2[] = | ||
"PYTHONHOME : alternate <prefix> directory (or <prefix>%lc<exec_prefix>).\n" | ||
" The default module search path uses %s.\n" | ||
"PYTHONPLATLIBDIR : override sys.platlibdir.\n" | ||
"PYTHONCASEOK : ignore case in 'import' statements (Windows).\n" | ||
"PYTHONUTF8: if set to 1, enable the UTF-8 mode.\n" | ||
"PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.\n" | ||
"PYTHONFAULTHANDLER: dump the Python traceback on fatal errors.\n"; | ||
static const char usage_6[] = | ||
static const char usage_envvars3[] = | ||
"PYTHONHASHSEED: if this variable is set to 'random', a random value is used\n" | ||
" to seed the hashes of str and bytes objects. It can also be set to an\n" | ||
" integer in the range [0,4294967295] to get hash values with a\n" | ||
|
@@ -2005,6 +2011,7 @@ _PyConfig_InitImportConfig(PyConfig *config) | |
// set, like -X showrefcount which requires a debug build. In this case unknown | ||
// options are silently ignored. | ||
const wchar_t* known_xoptions[] = { | ||
L"help", | ||
L"faulthandler", | ||
L"showrefcount", | ||
L"tracemalloc", | ||
|
@@ -2060,7 +2067,7 @@ config_read(PyConfig *config, int compute_path_config) | |
/* -X options */ | ||
const wchar_t* option = _Py_check_xoptions(&config->xoptions, known_xoptions); | ||
if (option != NULL) { | ||
return PyStatus_Error("Unknown value for option -X"); | ||
return PyStatus_Error("Unknown value for option -X (see -X help)"); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Turns out that showing the invalid value in this error message is not trivial: real C programmers had issue with it too before #28823 |
||
|
||
if (config_get_xoption(config, L"showrefcount")) { | ||
|
@@ -2216,12 +2223,25 @@ config_usage(int error, const wchar_t* program) | |
fputs(usage_1, f); | ||
fputs(usage_2, f); | ||
fputs(usage_3, f); | ||
fprintf(f, usage_4, (wint_t)DELIM); | ||
fprintf(f, usage_5, (wint_t)DELIM, PYTHONHOMEHELP); | ||
fputs(usage_6, f); | ||
fputs(usage_4, f); | ||
} | ||
} | ||
|
||
static void | ||
config_envvars_usage() | ||
{ | ||
FILE *f = stdout; | ||
fprintf(f, usage_envvars1, (wint_t)DELIM); | ||
fprintf(f, usage_envvars2, (wint_t)DELIM, PYTHONHOMEHELP); | ||
fputs(usage_envvars3, f); | ||
} | ||
|
||
static void | ||
config_xoptions_usage() | ||
{ | ||
FILE *f = stdout; | ||
fputs(usage_xoptions, f); | ||
} | ||
merwok marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/* Parse the command line arguments */ | ||
static PyStatus | ||
|
@@ -2232,6 +2252,7 @@ config_parse_cmdline(PyConfig *config, PyWideStringList *warnoptions, | |
const PyWideStringList *argv = &config->argv; | ||
int print_version = 0; | ||
const wchar_t* program = config->program_name; | ||
const wchar_t* xoption_help; | ||
merwok marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
_PyOS_ResetGetOpt(); | ||
do { | ||
|
@@ -2274,8 +2295,11 @@ config_parse_cmdline(PyConfig *config, PyWideStringList *warnoptions, | |
|
||
switch (c) { | ||
case 0: | ||
// Handle long option. | ||
assert(longindex == 0); // Only one long option now. | ||
// Handle long options. | ||
merwok marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert(longindex < 2); // Only two long options for now. | ||
switch(longindex) { | ||
case 0: | ||
merwok marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// check-hash-based-pycs | ||
if (wcscmp(_PyOS_optarg, L"always") == 0 | ||
|| wcscmp(_PyOS_optarg, L"never") == 0 | ||
|| wcscmp(_PyOS_optarg, L"default") == 0) | ||
|
@@ -2292,6 +2316,13 @@ config_parse_cmdline(PyConfig *config, PyWideStringList *warnoptions, | |
return _PyStatus_EXIT(2); | ||
} | ||
break; | ||
case 1: | ||
// help-env | ||
config_envvars_usage(); | ||
return _PyStatus_EXIT(0); | ||
break; | ||
merwok marked this conversation as resolved.
Show resolved
Hide resolved
merwok marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
break; | ||
|
||
case 'b': | ||
config->bytes_warning++; | ||
|
@@ -2308,7 +2339,6 @@ config_parse_cmdline(PyConfig *config, PyWideStringList *warnoptions, | |
|
||
case 'E': | ||
case 'I': | ||
case 'X': | ||
/* option handled by _PyPreCmdline_Read() */ | ||
break; | ||
|
||
|
@@ -2370,6 +2400,15 @@ config_parse_cmdline(PyConfig *config, PyWideStringList *warnoptions, | |
config->use_hash_seed = 0; | ||
break; | ||
|
||
case 'X': | ||
xoption_help = config_get_xoption(config, L"help"); | ||
if (xoption_help) { | ||
config_xoptions_usage(); | ||
return _PyStatus_EXIT(0); | ||
} | ||
/* option handled by _PyPreCmdline_Read() */ | ||
break; | ||
|
||
/* This space reserved for other options */ | ||
|
||
default: | ||
|
Uh oh!
There was an error while loading. Please reload this page.