user is shown help when typing lbrynet help
This commit is contained in:
parent
026d93e92a
commit
6e29f7e99b
2 changed files with 22 additions and 35 deletions
|
@ -141,6 +141,10 @@ class ArgumentParser(argparse.ArgumentParser):
|
||||||
self, action, "Commands", lambda parser: 'group' not in parser._defaults
|
self, action, "Commands", lambda parser: 'group' not in parser._defaults
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def error(self, message):
|
||||||
|
self.print_help(argparse._sys.stderr)
|
||||||
|
self.exit(2, '\n'+message+'\n')
|
||||||
|
|
||||||
|
|
||||||
class HelpFormatter(argparse.HelpFormatter):
|
class HelpFormatter(argparse.HelpFormatter):
|
||||||
|
|
||||||
|
@ -164,7 +168,9 @@ def add_command_parser(parent, command):
|
||||||
|
|
||||||
|
|
||||||
def get_argument_parser():
|
def get_argument_parser():
|
||||||
main = ArgumentParser('lbrynet')
|
main = ArgumentParser(
|
||||||
|
'lbrynet', description='An interface to the LBRY Network.'
|
||||||
|
)
|
||||||
main.add_argument(
|
main.add_argument(
|
||||||
'-v', '--version', dest='cli_version', action="store_true",
|
'-v', '--version', dest='cli_version', action="store_true",
|
||||||
help='Show lbrynet CLI version and exit.'
|
help='Show lbrynet CLI version and exit.'
|
||||||
|
@ -175,7 +181,7 @@ def get_argument_parser():
|
||||||
start = sub.add_parser(
|
start = sub.add_parser(
|
||||||
'start',
|
'start',
|
||||||
usage='lbrynet start [--config FILE] [--data-dir DIR] [--wallet-dir DIR] [--download-dir DIR] ...',
|
usage='lbrynet start [--config FILE] [--data-dir DIR] [--wallet-dir DIR] [--download-dir DIR] ...',
|
||||||
help='Start lbrynet API server.'
|
help='Start lbrynet network interface.'
|
||||||
)
|
)
|
||||||
start.add_argument(
|
start.add_argument(
|
||||||
'--quiet', dest='quiet', action="store_true",
|
'--quiet', dest='quiet', action="store_true",
|
||||||
|
|
|
@ -55,48 +55,29 @@ class CLITest(AsyncioTestCase):
|
||||||
self.assertEqual(3, normalize_value('3', key="some_other_thing"))
|
self.assertEqual(3, normalize_value('3', key="some_other_thing"))
|
||||||
|
|
||||||
def test_help(self):
|
def test_help(self):
|
||||||
self.assertIn(
|
self.assertIn('lbrynet [-v] [--api HOST:PORT]', self.shell(['--help']))
|
||||||
'Usage: lbrynet [-v] [--api HOST:PORT]', self.shell(['--help'])
|
|
||||||
)
|
|
||||||
# start is special command, with separate help handling
|
# start is special command, with separate help handling
|
||||||
self.assertIn(
|
self.assertIn('--share-usage-data', self.shell(['start', '--help']))
|
||||||
'--share-usage-data', self.shell(['start', '--help'])
|
|
||||||
)
|
|
||||||
# publish is ungrouped command, returns usage only implicitly
|
# publish is ungrouped command, returns usage only implicitly
|
||||||
self.assertIn(
|
self.assertIn('publish (<name> | --name=<name>)', self.shell(['publish']))
|
||||||
'publish (<name> | --name=<name>)', self.shell(['publish'])
|
|
||||||
)
|
|
||||||
# publish is ungrouped command, with explicit --help
|
# publish is ungrouped command, with explicit --help
|
||||||
self.assertIn(
|
self.assertIn('Make a new name claim and publish', self.shell(['publish', '--help']))
|
||||||
'Make a new name claim and publish', self.shell(['publish', '--help'])
|
|
||||||
)
|
|
||||||
# account is a group, returns help implicitly
|
# account is a group, returns help implicitly
|
||||||
self.assertIn(
|
self.assertIn('Return the balance of an account', self.shell(['account']))
|
||||||
'Return the balance of an account',
|
|
||||||
self.shell(['account'])
|
|
||||||
)
|
|
||||||
# account is a group, with explicit --help
|
# account is a group, with explicit --help
|
||||||
self.assertIn(
|
self.assertIn('Return the balance of an account', self.shell(['account', '--help']))
|
||||||
'Return the balance of an account',
|
|
||||||
self.shell(['account', '--help'])
|
|
||||||
)
|
|
||||||
# account add is a grouped command, returns usage implicitly
|
# account add is a grouped command, returns usage implicitly
|
||||||
self.assertIn(
|
self.assertIn('account_add (<account_name> | --account_name=<account_name>)', self.shell(['account', 'add']))
|
||||||
'account_add (<account_name> | --account_name=<account_name>)',
|
|
||||||
self.shell(['account', 'add'])
|
|
||||||
)
|
|
||||||
# account add is a grouped command, with explicit --help
|
# account add is a grouped command, with explicit --help
|
||||||
self.assertIn(
|
self.assertIn('Add a previously created account from a seed,', self.shell(['account', 'add', '--help']))
|
||||||
'Add a previously created account from a seed,', self.shell(['account', 'add', '--help'])
|
|
||||||
)
|
def test_help_error_handling(self):
|
||||||
|
# person tries `help` command, then they get help even though that's invalid command
|
||||||
|
self.assertIn('--config FILE', self.shell(['help']))
|
||||||
# help for invalid command, with explicit --help
|
# help for invalid command, with explicit --help
|
||||||
self.assertIn(
|
self.assertIn('--config FILE', self.shell(['nonexistant', '--help']))
|
||||||
"invalid choice: 'publish1'", self.shell(['publish1', '--help'])
|
|
||||||
)
|
|
||||||
# help for invalid command, implicit
|
# help for invalid command, implicit
|
||||||
self.assertIn(
|
self.assertIn('--config FILE', self.shell(['nonexistant']))
|
||||||
"invalid choice: 'publish1'", self.shell(['publish1'])
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_version_command(self):
|
def test_version_command(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|
Loading…
Reference in a new issue