Merge pull request #3148 from ThomasWaldmann/maincommand-help

don't crash if only a global option is given, show help, fixes #3142
This commit is contained in:
TW 2017-10-12 20:32:35 +02:00 committed by GitHub
commit de175a7ed1
2 changed files with 11 additions and 0 deletions

View File

@ -30,3 +30,11 @@ Common options
All Borg commands share these options: All Borg commands share these options:
.. include:: common-options.rst.inc .. include:: common-options.rst.inc
Examples
~~~~~~~~
::
# Create an archive and log: borg version, files list, return code
$ borg create --show-version --list --show-rc /path/to/repo::my-files files

View File

@ -1959,6 +1959,8 @@ class Archiver:
parser.print_help() parser.print_help()
return EXIT_SUCCESS return EXIT_SUCCESS
do_maincommand_help = do_subcommand_help
def preprocess_args(self, args): def preprocess_args(self, args):
deprecations = [ deprecations = [
# ('--old', '--new' or None, 'Warning: "--old" has been deprecated. Use "--new" instead.'), # ('--old', '--new' or None, 'Warning: "--old" has been deprecated. Use "--new" instead.'),
@ -2226,6 +2228,7 @@ class Archiver:
parser = argparse.ArgumentParser(prog=self.prog, description='Borg - Deduplicated Backups', parser = argparse.ArgumentParser(prog=self.prog, description='Borg - Deduplicated Backups',
add_help=False) add_help=False)
parser.set_defaults(func=functools.partial(self.do_maincommand_help, parser))
parser.common_options = self.CommonOptions(define_common_options, parser.common_options = self.CommonOptions(define_common_options,
suffix_precedence=('_maincommand', '_midcommand', '_subcommand')) suffix_precedence=('_maincommand', '_midcommand', '_subcommand'))
parser.add_argument('-V', '--version', action='version', version='%(prog)s ' + __version__, parser.add_argument('-V', '--version', action='version', version='%(prog)s ' + __version__,