8000 gh-90300: split --help output into separate options by merwok · Pull Request #30331 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 33 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
225c869
move list of X options out of help output
merwok Jan 2, 2022
eaefd1a
mention help option in fatal error message
merwok Jan 2, 2022
57fd33b
move variable declaration out of case block
merwok Jan 2, 2022
55dbf69
move extra envvars help to separate option
merwok Jan 2, 2022
0aaf9af
doc
merwok Jan 2, 2022
a592003
add minimal tests
merwok Jan 2, 2022
1c4cf63
flatten the sub-switch
merwok Jan 2, 2022
d8bfcff
suggestion from Barry
merwok Jan 3, 2022
38f2dd8
more suggestions from flufl
merwok Jan 3, 2022
a828fe8
remove unnecessary
merwok Jan 7, 2022
8bde4ec
mention all envvars in --help-env
merwok Jan 7, 2022
0dbaf03
mistake
merwok Jan 7, 2022
0c9a995
introduce --help-xoptions
merwok Jan 12, 2022
aab464f
add --help-all
merwok Jan 12, 2022
064d4ad
merge upstream
merwok Jan 12, 2022
b9a0b19
replace fprintf by printf; remove extra blanklines
merwok Jan 15, 2022
0ee24d4
merge upstream
merwok Feb 9, 2022
dd2beaa
Merge branch 'main' into shorten-help-output
merwok Apr 11, 2022
c74fc69
merge upstream
merwok May 5, 2022
2f108fe
merge upstream
merwok May 23, 2022
4f345e8
check return code in verify_valid_flag
merwok May 23, 2022
a6573d6
remove duplicate check
merwok May 24, 2022
da97a38
fix some help texts in 80 columns
merwok May 24, 2022
98525b4
remove needless checks
merwok May 25, 2022
5585095
reformat and rearrange some help entries
merwok May 25, 2022
24526bd
fix formatting issues and missing info in man page and --help
merwok May 25, 2022
0bb5dfa
make new tests a bit more useful
merwok May 25, 2022
8fa72f5
512 bytes should be enough for everyone
merwok May 25, 2022
29d04a0
keep long option at the end of help text
merwok May 26, 2022
356d1bf
merge branch 'fix-help-man'
merwok May 26, 2022
ac1b5fb
fix tests and output
merwok May 26, 2022
9bcea95
final fixes
merwok May 26, 2022
5485255
merge upstream
merwok May 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move extra envvars help to separate option
  • Loading branch information
merwok committed Jan 2, 2022
commit 55dbf698193f32974337752605316030da04d74f
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add ``-X help`` and ``--help-env`` options and make ``--help`` output
shorter.
19 changes: 17 additions & 2 deletions Misc/python.man
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ python \- an interpreted, interactive, object-oriented programming language
.B \-x
]
[
[
.B \-X
.I option
]
[
.B \-?
]
.br
Expand All @@ -81,6 +81,16 @@ python \- an interpreted, interactive, object-oriented programming language
|
.I never
]
.br
[
.B \--help
]
[
.B \--help-env
]
[
.B \-X help
]
Copy link
Member Author

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions Python/getopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static const wchar_t *opt_ptr = L"";

static const _PyOS_LongOption longopts[] = {
{L"check-hash-based-pycs", 1, 0},
{L"help-env", 0, 0},
{NULL, 0, 0},
};

Expand Down
51 changes: 37 additions & 14 deletions Python/initconfig.c
8000
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,19 @@ static const char usage_3[] = "\
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 (see details with -X help)\n\
--check-hash-based-pycs always|default|never:\n\
--help-env : print help about other environment variables\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\
";

static const char usage_xoptions[] = "\
The following implementation-specific options are available:\n\
-X help: show this help\n\
-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\
Expand Down Expand Up @@ -104,24 +112,21 @@ The following implementation-specific options are available:\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\
";
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"
Expand Down Expand Up @@ -2218,16 +2223,24 @@ 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()
{
fputs(usage_xoptions, stdout);
FILE *f = stdout;
fputs(usage_xoptions, f);
}

/* Parse the command line arguments */
Expand Down Expand Up @@ -2282,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.
assert(longindex < 2); // Only two long options for now.
switch(longindex) {
case 0:
// check-hash-based-pycs
if (wcscmp(_PyOS_optarg, L"always") == 0
|| wcscmp(_PyOS_optarg, L"never") == 0
|| wcscmp(_PyOS_optarg, L"default") == 0)
Expand All @@ -2300,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;
}
break;

case 'b':
config->bytes_warning++;
Expand Down
0