diff options
author | Jelmer Vernooij <jelmer@jelmer.uk> | 2017-03-01 20:10:54 +0000 |
---|---|---|
committer | Jelmer Vernooij <jelmer@jelmer.uk> | 2017-03-01 20:10:54 +0000 |
commit | a6157569c288dc6586145b1f4425b23aa88eaecd (patch) | |
tree | bb4ac5f711c99cf25e1645465e3bbaa352131746 | |
parent | 4112b6365f604a39f85f6e1e02980ae49d209ce9 (diff) |
Fix remote commands in command-line tool.
-rwxr-xr-x | bin/dulwich | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/bin/dulwich b/bin/dulwich index c2c0b8a4..f64d2fa4 100755 --- a/bin/dulwich +++ b/bin/dulwich @@ -468,18 +468,31 @@ class cmd_pack_objects(Command): f.close() -def cmd_remote_add(args): - parser = optparse.OptionParser() - options, args = parser.parse_args(args) - porcelain.remote_add('.', args[0], args[1]) +class cmd_remote_add(Command): + def run(self, args): + parser = optparse.OptionParser() + options, args = parser.parse_args(args) + porcelain.remote_add('.', args[0], args[1]) + + +class cmd_remote(Command): -def cmd_remote(args): subcommands = { "add": cmd_remote_add, } - cmd = args[0] - return subcommands[cmd](args[1:]) + + def run(self, args): + if not args: + print("Supported subcommands: %s" % ', '.join(self.subcommands.keys())) + return False + cmd = args[0] + try: + cmd_kls = self.subcommands[cmd] + except KeyError: + print('No such subcommand: %s' % args[0]) + return False + return cmd_kls(args[1:]) class cmd_help(Command): @@ -543,7 +556,10 @@ if len(sys.argv) < 2: sys.exit(1) cmd = sys.argv[1] -if not cmd in commands: +try: + cmd_kls = commands[cmd] +except KeyError: print("No such subcommand: %s" % cmd) sys.exit(1) -commands[cmd]().run(sys.argv[2:]) +# TODO(jelmer): Return non-0 on errors +cmd_kls().run(sys.argv[2:]) |