Repository: cloudstack-cloudmonkey Updated Branches: refs/heads/master 61d6b98bc -> 2d709cab3
cloudmonkey: use argparse instead of option parser Signed-off-by: Rohit Yadav <rohit.ya...@shapeblue.com> Project: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/commit/9e468f58 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/tree/9e468f58 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/diff/9e468f58 Branch: refs/heads/master Commit: 9e468f584b386e963153f3d3e9bd6795a8e09be5 Parents: 61d6b98 Author: Rohit Yadav <rohit.ya...@shapeblue.com> Authored: Tue Sep 2 01:31:11 2014 +0200 Committer: Rohit Yadav <rohit.ya...@shapeblue.com> Committed: Tue Sep 2 01:31:11 2014 +0200 ---------------------------------------------------------------------- cloudmonkey/cloudmonkey.py | 44 +++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/blob/9e468f58/cloudmonkey/cloudmonkey.py ---------------------------------------------------------------------- diff --git a/cloudmonkey/cloudmonkey.py b/cloudmonkey/cloudmonkey.py index b74afea..1d3893d 100644 --- a/cloudmonkey/cloudmonkey.py +++ b/cloudmonkey/cloudmonkey.py @@ -18,6 +18,8 @@ # under the License. try: + import argcomplete + import argparse import atexit import cmd import json @@ -559,39 +561,25 @@ class CloudMonkeyShell(cmd.Cmd, object): return self.do_EOF(args) -class MonkeyParser(OptionParser): - def format_help(self, formatter=None): - if formatter is None: - formatter = self.formatter - result = [] - if self.usage: - result.append("Usage: cloudmonkey [options] [cmds] [params]\n\n") - if self.description: - result.append(self.format_description(formatter) + "\n") - result.append(self.format_option_help(formatter)) - result.append("\nTry cloudmonkey [help|?]\n") - return "".join(result) - - def main(): - parser = MonkeyParser() - parser.add_option("-c", "--config-file", - dest="cfile", default=config_file, + parser = argparse.ArgumentParser(usage="cloudmonkey [options] [commands]", + version="cloudmonkey " + __version__, + description=__description__, + epilog="Try cloudmonkey [help|?]") + parser.add_argument("-c", "--config-file", + dest="configFile", default=config_file, help="config file for cloudmonkey", metavar="FILE") - parser.add_option("-v", "--version", - action="store_true", dest="version", default=False, - help="prints cloudmonkey version information") - (options, args) = parser.parse_args() - if options.version: - print "cloudmonkey", __version__ - print __description__, "(%s)" % __projecturl__ - sys.exit(0) + parser.add_argument("commands", nargs=argparse.REMAINDER, + help="api commands") + + argcomplete.autocomplete(parser) + args = parser.parse_args() - shell = CloudMonkeyShell(sys.argv[0], options.cfile) + shell = CloudMonkeyShell(sys.argv[0], args.configFile) - if len(args) > 0: - shell.onecmd(' '.join(args)) + if len(args.commands) > 0: + shell.onecmd(' '.join(args.commands)) else: shell.cmdloop()