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
This commit is contained in:
committed by
Darragh Bailey
parent
0d214767e0
commit
2e45b5580c
@@ -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
|
||||
|
||||
@@ -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 <branch>]
|
||||
[--import-branch <import-branch>] [<upstream-branch>]
|
||||
[<branches> ...]
|
||||
%(prog)s [--finish] [options] [--onto <branch>]
|
||||
[--import-branch <import-branch>]
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(ImportCommand, self).__init__(*args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user