From 7d1c6c79804941d8562a1f2528637e1479571db3 Mon Sep 17 00:00:00 2001 From: rofl0r Date: Wed, 18 Sep 2013 20:08:41 +0200 Subject: [PATCH] fix help text when invoked with --help the built-in optparser help text did not show the available commands closes #304 --- electrum | 53 +++++++++++++++++++++++++++++++++-------------------- 1 files changed, 33 insertions(+), 20 deletions(-) diff --git a/electrum b/electrum index 9a8ce80..cca0cff 100755 --- a/electrum +++ b/electrum @@ -66,7 +66,8 @@ def prompt_password(prompt, confirm=True): def arg_parser(): usage = "%prog [options] command" - parser = optparse.OptionParser(prog=usage) + parser = optparse.OptionParser(prog=usage, add_help_option = False) + parser.add_option("-h", "--help", action="callback", callback=print_help_cb, help="show this help text") parser.add_option("-g", "--gui", dest="gui", help="User interface: qt, lite, gtk or text") parser.add_option("-w", "--wallet", dest="wallet_path", help="wallet path (default: electrum.dat)") parser.add_option("-o", "--offline", action="store_true", dest="offline", default=False, help="remain offline") @@ -85,6 +86,35 @@ def arg_parser(): parser.add_option("-G", "--gap", dest="gap_limit", default=None, help="gap limit") return parser +def print_help(parser): + parser.print_help() + print_msg("Type 'electrum help ' to see the help for a specific command") + print_msg("Type 'electrum --help' to see the list of options") + run_command('help') + exit(1) + +def print_help_cb(self, opt, value, parser): + print_help(parser) + +def run_command(cmd): + cmd_runner = Commands(wallet, network) + func = eval('cmd_runner.' + cmd) + if cmd == 'help': + password = None + args = [] + cmd_runner.password = password + try: + result = func(*args[1:]) + except BaseException, e: + import traceback + traceback.print_exc(file=sys.stdout) + sys.exit(1) + + if type(result) == str: + util.print_msg(result) + elif result is not None: + util.print_json(result) + if __name__ == '__main__': @@ -278,10 +308,7 @@ if __name__ == '__main__': elif cmd == 'help': if len(args) < 2: - parser.print_help() - print_msg("Type 'electrum help ' to see the help for a specific command") - print_msg("Type 'electrum --help' to see the list of options") - + print_help(parser) @@ -354,21 +381,7 @@ if __name__ == '__main__': wallet.update_password(seed, password, new_password) else: - cmd_runner = Commands(wallet, network) - func = eval('cmd_runner.' + cmd) - cmd_runner.password = password - try: - result = func(*args[1:]) - except BaseException, e: - import traceback - traceback.print_exc(file=sys.stdout) - sys.exit(1) - - if type(result) == str: - util.print_msg(result) - elif result is not None: - util.print_json(result) - + run_command(cmd) if cmd not in offline_commands and not options.offline: -- 1.7.1