[cli] Add -H/--full-help and only show command list by default

The full help has gotten too long, just print the commands by default.
This commit is contained in:
derrod 2021-12-22 08:20:36 +01:00
parent 11850228a8
commit 0e72950382

View file

@ -1902,10 +1902,12 @@ def main():
help='Specify custom config file or name for the config file in the default directory.') help='Specify custom config file or name for the config file in the default directory.')
parser.add_argument('-J', '--pretty-json', dest='pretty_json', action='store_true', parser.add_argument('-J', '--pretty-json', dest='pretty_json', action='store_true',
help='Pretty-print JSON') help='Pretty-print JSON')
parser.add_argument('-H', '--full-help', dest='full_help', action='store_true',
help='Show full help (including individual command help)')
# all the commands # all the commands
subparsers = parser.add_subparsers(title='Commands', dest='subparser_name') subparsers = parser.add_subparsers(title='Commands', dest='subparser_name', metavar='<command>')
auth_parser = subparsers.add_parser('auth', help='Authenticate with EPIC') auth_parser = subparsers.add_parser('auth', help='Authenticate with the Epic Games Store')
install_parser = subparsers.add_parser('install', help='Download a game', install_parser = subparsers.add_parser('install', help='Download a game',
aliases=('download', 'update', 'repair'), aliases=('download', 'update', 'repair'),
usage='%(prog)s <App Name> [options]', usage='%(prog)s <App Name> [options]',
@ -2191,21 +2193,20 @@ def main():
print(f'legendary version "{__version__}", codename "{__codename__}"') print(f'legendary version "{__version__}", codename "{__codename__}"')
exit(0) exit(0)
if args.subparser_name not in ('auth', 'list-games', 'list-installed', 'list-files', if not args.subparser_name or args.full_help:
'launch', 'download', 'uninstall', 'install', 'update',
'repair', 'list-saves', 'download-saves', 'sync-saves',
'clean-saves', 'verify-game', 'import-game', 'egl-sync',
'status', 'info', 'alias', 'cleanup', 'activate', 'get-token'):
print(parser.format_help()) print(parser.format_help())
# Print the main help *and* the help for all of the subcommands. Thanks stackoverflow! if args.full_help:
print('Individual command help:') # Commands that should not be shown in full help/list of commands (e.g. aliases)
subparsers = next(a for a in parser._actions if isinstance(a, argparse._SubParsersAction)) _hidden_commands = {'download', 'update', 'repair', 'get-token'}
for choice, subparser in subparsers.choices.items(): # Print the help for all of the subparsers. Thanks stackoverflow!
if choice in ('download', 'update', 'repair', 'get-token'): print('Individual command help:')
continue subparsers = next(a for a in parser._actions if isinstance(a, argparse._SubParsersAction))
print(f'\nCommand: {choice}') for choice, subparser in subparsers.choices.items():
print(subparser.format_help()) if choice in _hidden_commands:
continue
print(f'\nCommand: {choice}')
print(subparser.format_help())
return return
cli = LegendaryCLI(override_config=args.config_file) cli = LegendaryCLI(override_config=args.config_file)