add a borg debug/key dummy command, fixes #1932

the problem was that there neither was a do_debug implementation for the case
someone just enters "borg debug", nor did the parser inherit from common_parser
(so accessing .umask triggered an exception before setup_logging() was called,
which triggered another exception when log output should have been emitted).

same for do_key ("borg key").

added a generic handler that just prints the subcommand help.
This commit is contained in:
Thomas Waldmann 2016-12-14 00:00:09 +01:00
parent d13854853c
commit 5a40870416
1 changed files with 9 additions and 2 deletions

View File

@ -992,6 +992,11 @@ class Archiver:
parser.error('No help available on %s' % (args.topic,)) parser.error('No help available on %s' % (args.topic,))
return self.exit_code return self.exit_code
def do_subcommand_help(self, parser, args):
"""display infos about subcommand"""
parser.print_help()
return EXIT_SUCCESS
def preprocess_args(self, args): def preprocess_args(self, args):
deprecations = [ deprecations = [
# ('--old', '--new', 'Warning: "--old" has been deprecated. Use "--new" instead.'), # ('--old', '--new', 'Warning: "--old" has been deprecated. Use "--new" instead.'),
@ -1148,13 +1153,14 @@ class Archiver:
subparser.add_argument('location', metavar='REPOSITORY', nargs='?', default='', subparser.add_argument('location', metavar='REPOSITORY', nargs='?', default='',
type=location_validator(archive=False)) type=location_validator(archive=False))
subparser = subparsers.add_parser('key', subparser = subparsers.add_parser('key', parents=[common_parser],
description="Manage a keyfile or repokey of a repository", description="Manage a keyfile or repokey of a repository",
epilog="", epilog="",
formatter_class=argparse.RawDescriptionHelpFormatter, formatter_class=argparse.RawDescriptionHelpFormatter,
help='manage repository key') help='manage repository key')
key_parsers = subparser.add_subparsers(title='required arguments', metavar='<command>') key_parsers = subparser.add_subparsers(title='required arguments', metavar='<command>')
subparser.set_defaults(func=functools.partial(self.do_subcommand_help, subparser))
key_export_epilog = textwrap.dedent(""" key_export_epilog = textwrap.dedent("""
If repository encryption is used, the repository is inaccessible If repository encryption is used, the repository is inaccessible
@ -1681,13 +1687,14 @@ class Archiver:
in case you ever run into some severe malfunction. Use them only if you know in case you ever run into some severe malfunction. Use them only if you know
what you are doing or if a trusted developer tells you what to do.""") what you are doing or if a trusted developer tells you what to do.""")
subparser = subparsers.add_parser('debug', subparser = subparsers.add_parser('debug', parents=[common_parser],
description='debugging command (not intended for normal use)', description='debugging command (not intended for normal use)',
epilog=debug_epilog, epilog=debug_epilog,
formatter_class=argparse.RawDescriptionHelpFormatter, formatter_class=argparse.RawDescriptionHelpFormatter,
help='debugging command (not intended for normal use)') help='debugging command (not intended for normal use)')
debug_parsers = subparser.add_subparsers(title='required arguments', metavar='<command>') debug_parsers = subparser.add_subparsers(title='required arguments', metavar='<command>')
subparser.set_defaults(func=functools.partial(self.do_subcommand_help, subparser))
debug_info_epilog = textwrap.dedent(""" debug_info_epilog = textwrap.dedent("""
This command displays some system information that might be useful for bug This command displays some system information that might be useful for bug