From 2e45b5580c2a299282469df609f527a8e16434bf Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Sat, 12 Dec 2015 17:01:53 +0000 Subject: [PATCH] Add more complex usage summary for import command Add a more complex usage summary for the import command, making it easier to see that '--finish' is a separate mode of operation. Include a fix to prevent an exception where a command doc string is not defined. Change-Id: I1b8d835d0cd9a574d799d2e4abeaf8f19e76ba1b --- git_upstream/commands/__init__.py | 18 ++++++++++++------ git_upstream/commands/import.py | 7 +++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/git_upstream/commands/__init__.py b/git_upstream/commands/__init__.py index 67225cd..afc641c 100644 --- a/git_upstream/commands/__init__.py +++ b/git_upstream/commands/__init__.py @@ -19,6 +19,7 @@ import abc import argparse import os +import textwrap class AppendReplaceAction(argparse._AppendAction): @@ -46,6 +47,7 @@ class GitUpstreamCommand(object): """ __metaclass__ = abc.ABCMeta + usage = "" def __init__(self, parser): self.parser = parser @@ -81,13 +83,17 @@ def _find_actions(subparsers, module_path): for cmd_class in GitUpstreamCommand.__subclasses__(): command = cmd_class.name - desc = cmd_class.__doc__ or None - help = desc.strip().split('\n')[0] + desc = cmd_class.__doc__ or '' - subparser = subparsers.add_parser( - command, - help=help, - description=desc) + parser_kwargs = { + 'help': desc.strip().split('\n')[0], + 'description': desc, + } + + if cmd_class.usage: + parser_kwargs['usage'] = textwrap.dedent(cmd_class.usage) + + subparser = subparsers.add_parser(command, **parser_kwargs) subparser.register('action', 'append_replace', AppendReplaceAction) subparser.set_defaults(cmd=cmd_class(subparser)) subcommands[command] = subparser diff --git a/git_upstream/commands/import.py b/git_upstream/commands/import.py index f1d4276..bb98613 100644 --- a/git_upstream/commands/import.py +++ b/git_upstream/commands/import.py @@ -36,6 +36,13 @@ class ImportCommand(LogDedentMixin, GitUpstreamCommand): with those from the import branch, unless --no-merge is specified. """ name = "import" + usage = """ + %(prog)s [-i] [options] [--onto ] + [--import-branch ] [] + [ ...] + %(prog)s [--finish] [options] [--onto ] + [--import-branch ] + """ def __init__(self, *args, **kwargs): super(ImportCommand, self).__init__(*args, **kwargs)