Respect the user's NO_COLOR environment variable.
This commit is contained in:
parent
2a6bc2a306
commit
c7f4d1dbf9
1 changed files with 12 additions and 9 deletions
|
@ -555,7 +555,8 @@ def _go_single(parser, argv, *, args_postprocessor=None):
|
||||||
len(argv) == 0 and not can_bare
|
len(argv) == 0 and not can_bare
|
||||||
)
|
)
|
||||||
if needs_help:
|
if needs_help:
|
||||||
print_helptext(make_helptext(parser))
|
do_colors = os.environ.get('NO_COLOR', None) is None
|
||||||
|
print_helptext(make_helptext(parser, do_colors=do_colors))
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
|
@ -579,22 +580,24 @@ def _go_multi(parser, argv, *, args_postprocessor=None):
|
||||||
if command == '' and can_bare:
|
if command == '' and can_bare:
|
||||||
return main(argv)
|
return main(argv)
|
||||||
|
|
||||||
|
do_colors = os.environ.get('NO_COLOR', None) is None
|
||||||
|
|
||||||
|
if command == 'helpall':
|
||||||
|
print_helptext(make_helptext(parser, full_subparsers=True, all_command_names=all_command_names, do_colors=do_colors))
|
||||||
|
return 1
|
||||||
|
|
||||||
if command == '':
|
if command == '':
|
||||||
print_helptext(make_helptext(parser, all_command_names=all_command_names))
|
print_helptext(make_helptext(parser, all_command_names=all_command_names, do_colors=do_colors))
|
||||||
because = 'you did not choose a command'
|
because = 'you did not choose a command'
|
||||||
pipeable.stderr(f'\nYou are seeing the default help text because {because}.')
|
pipeable.stderr(f'\nYou are seeing the default help text because {because}.')
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if command == 'helpall':
|
|
||||||
print_helptext(make_helptext(parser, full_subparsers=True, all_command_names=all_command_names))
|
|
||||||
return 1
|
|
||||||
|
|
||||||
if command in HELP_COMMANDS:
|
if command in HELP_COMMANDS:
|
||||||
print_helptext(make_helptext(parser, all_command_names=all_command_names))
|
print_helptext(make_helptext(parser, all_command_names=all_command_names, do_colors=do_colors))
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if command not in subparsers:
|
if command not in subparsers:
|
||||||
print_helptext(make_helptext(parser, all_command_names=all_command_names))
|
print_helptext(make_helptext(parser, all_command_names=all_command_names, do_colors=do_colors))
|
||||||
because = f'"{command}" was not recognized'
|
because = f'"{command}" was not recognized'
|
||||||
pipeable.stderr(f'\nYou are seeing the default help text because {because}.')
|
pipeable.stderr(f'\nYou are seeing the default help text because {because}.')
|
||||||
return 1
|
return 1
|
||||||
|
@ -604,7 +607,7 @@ def _go_multi(parser, argv, *, args_postprocessor=None):
|
||||||
|
|
||||||
no_args = len(arguments) == 0 and not can_use_bare(subparser)
|
no_args = len(arguments) == 0 and not can_use_bare(subparser)
|
||||||
if no_args or any(arg.lower() in HELP_ARGS for arg in arguments):
|
if no_args or any(arg.lower() in HELP_ARGS for arg in arguments):
|
||||||
print_helptext(make_helptext(subparser, command_name=command, all_command_names=all_command_names))
|
print_helptext(make_helptext(subparser, command_name=command, all_command_names=all_command_names, do_colors=do_colors))
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
return main(argv)
|
return main(argv)
|
||||||
|
|
Loading…
Reference in a new issue