user is shown help when typing lbrynet help

This commit is contained in:
Lex Berezhny 2019-01-25 19:58:43 -05:00
parent 026d93e92a
commit 6e29f7e99b
2 changed files with 22 additions and 35 deletions

View file

@ -141,6 +141,10 @@ class ArgumentParser(argparse.ArgumentParser):
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):
@ -164,7 +168,9 @@ def add_command_parser(parent, command):
def get_argument_parser():
main = ArgumentParser('lbrynet')
main = ArgumentParser(
'lbrynet', description='An interface to the LBRY Network.'
)
main.add_argument(
'-v', '--version', dest='cli_version', action="store_true",
help='Show lbrynet CLI version and exit.'
@ -175,7 +181,7 @@ def get_argument_parser():
start = sub.add_parser(
'start',
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(
'--quiet', dest='quiet', action="store_true",

View file

@ -55,48 +55,29 @@ class CLITest(AsyncioTestCase):
self.assertEqual(3, normalize_value('3', key="some_other_thing"))
def test_help(self):
self.assertIn(
'Usage: lbrynet [-v] [--api HOST:PORT]', self.shell(['--help'])
)
self.assertIn('lbrynet [-v] [--api HOST:PORT]', self.shell(['--help']))
# start is special command, with separate help handling
self.assertIn(
'--share-usage-data', self.shell(['start', '--help'])
)
self.assertIn('--share-usage-data', self.shell(['start', '--help']))
# publish is ungrouped command, returns usage only implicitly
self.assertIn(
'publish (<name> | --name=<name>)', self.shell(['publish'])
)
self.assertIn('publish (<name> | --name=<name>)', self.shell(['publish']))
# publish is ungrouped command, with explicit --help
self.assertIn(
'Make a new name claim and publish', self.shell(['publish', '--help'])
)
self.assertIn('Make a new name claim and publish', self.shell(['publish', '--help']))
# account is a group, returns help implicitly
self.assertIn(
'Return the balance of an account',
self.shell(['account'])
)
self.assertIn('Return the balance of an account', self.shell(['account']))
# account is a group, with explicit --help
self.assertIn(
'Return the balance of an account',
self.shell(['account', '--help'])
)
self.assertIn('Return the balance of an account', self.shell(['account', '--help']))
# account add is a grouped command, returns usage implicitly
self.assertIn(
'account_add (<account_name> | --account_name=<account_name>)',
self.shell(['account', 'add'])
)
self.assertIn('account_add (<account_name> | --account_name=<account_name>)', self.shell(['account', 'add']))
# account add is a grouped command, with explicit --help
self.assertIn(
'Add a previously created account from a seed,', self.shell(['account', 'add', '--help'])
)
self.assertIn('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
self.assertIn(
"invalid choice: 'publish1'", self.shell(['publish1', '--help'])
)
self.assertIn('--config FILE', self.shell(['nonexistant', '--help']))
# help for invalid command, implicit
self.assertIn(
"invalid choice: 'publish1'", self.shell(['publish1'])
)
self.assertIn('--config FILE', self.shell(['nonexistant']))
def test_version_command(self):
self.assertEqual(