commands: Move to using a help attribute instead of __doc__
This commit is contained in:
parent
f89169d551
commit
2f6ecd9171
@ -20,7 +20,7 @@ class LocalCommand(command.Command):
|
||||
|
||||
|
||||
class ScanCommand(command.Command):
|
||||
"""Scan local media files and populate the local library."""
|
||||
help = "Scan local media files and populate the local library."
|
||||
|
||||
def __init__(self):
|
||||
super(ScanCommand, self).__init__()
|
||||
|
||||
@ -136,7 +136,7 @@ class RootCommand(command.Command):
|
||||
|
||||
|
||||
class ConfigCommand(command.Command):
|
||||
"""Show currently active configuration."""
|
||||
help = "Show currently active configuration."
|
||||
|
||||
def __init__(self):
|
||||
super(ConfigCommand, self).__init__()
|
||||
@ -148,7 +148,7 @@ class ConfigCommand(command.Command):
|
||||
|
||||
|
||||
class DepsCommand(command.Command):
|
||||
"""Show dependencies and debug information."""
|
||||
help = "Show dependencies and debug information."
|
||||
|
||||
def __init__(self):
|
||||
super(DepsCommand, self).__init__()
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import argparse
|
||||
import collections
|
||||
import os
|
||||
@ -31,6 +33,8 @@ class _HelpAction(argparse.Action):
|
||||
|
||||
|
||||
class Command(object):
|
||||
help = None
|
||||
|
||||
def __init__(self):
|
||||
self._children = collections.OrderedDict()
|
||||
self._arguments = []
|
||||
@ -78,8 +82,8 @@ class Command(object):
|
||||
formatter = argparse.HelpFormatter(prog)
|
||||
formatter.add_usage(None, actions, [])
|
||||
|
||||
if self.__doc__:
|
||||
formatter.add_text(self.__doc__)
|
||||
if self.help:
|
||||
formatter.add_text(self.help)
|
||||
|
||||
if actions:
|
||||
formatter.add_text('OPTIONS:')
|
||||
@ -100,11 +104,11 @@ class Command(object):
|
||||
def _subhelp(self, name, result):
|
||||
actions = self._build()[1]
|
||||
|
||||
if self.__doc__ or actions:
|
||||
if self.help or actions:
|
||||
formatter = argparse.HelpFormatter(name)
|
||||
formatter.add_usage(None, actions, [], '')
|
||||
formatter.start_section(None)
|
||||
formatter.add_text(self.__doc__)
|
||||
formatter.add_text(self.help)
|
||||
formatter.start_section(None)
|
||||
formatter.add_arguments(actions)
|
||||
formatter.end_section()
|
||||
|
||||
@ -293,7 +293,7 @@ class HelpTest(unittest.TestCase):
|
||||
|
||||
def test_command_with_documentation(self):
|
||||
cmd = command.Command()
|
||||
cmd.__doc__ = 'some text about everything this command does.'
|
||||
cmd.help = 'some text about everything this command does.'
|
||||
|
||||
expected = ('usage: foo\n\n'
|
||||
'some text about everything this command does.')
|
||||
@ -301,7 +301,7 @@ class HelpTest(unittest.TestCase):
|
||||
|
||||
def test_command_with_documentation_and_option(self):
|
||||
cmd = command.Command()
|
||||
cmd.__doc__ = 'some text about everything this command does.'
|
||||
cmd.help = 'some text about everything this command does.'
|
||||
cmd.add_argument('-h', '--help', action='store_true',
|
||||
help='show this message')
|
||||
|
||||
@ -320,7 +320,7 @@ class HelpTest(unittest.TestCase):
|
||||
|
||||
def test_subcommand_with_documentation_shown(self):
|
||||
child = command.Command()
|
||||
child.__doc__ = 'some text about everything this command does.'
|
||||
child.help = 'some text about everything this command does.'
|
||||
|
||||
cmd = command.Command()
|
||||
cmd.add_child('bar', child)
|
||||
@ -359,7 +359,7 @@ class HelpTest(unittest.TestCase):
|
||||
|
||||
def test_subcommand_with_options_and_documentation(self):
|
||||
child = command.Command()
|
||||
child.__doc__ = ' some text about everything this command does.'
|
||||
child.help = ' some text about everything this command does.'
|
||||
child.add_argument('-h', '--help', action='store_true',
|
||||
help='show this message')
|
||||
|
||||
@ -428,11 +428,11 @@ class HelpTest(unittest.TestCase):
|
||||
|
||||
def test_command_with_options_doc_and_subcommand_with_option_and_doc(self):
|
||||
child = command.Command()
|
||||
child.__doc__ = 'some text about this sub-command.'
|
||||
child.help = 'some text about this sub-command.'
|
||||
child.add_argument('--test', help='the great and wonderful')
|
||||
|
||||
cmd = command.Command()
|
||||
cmd.__doc__ = 'some text about everything this command does.'
|
||||
cmd.help = 'some text about everything this command does.'
|
||||
cmd.add_argument('-h', '--help', action='store_true',
|
||||
help='show this message')
|
||||
cmd.add_child('bar', child)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user