From 9f1d08c54be21487476a9e7b5779bc05ff862ee3 Mon Sep 17 00:00:00 2001 From: Aanand Prasad Date: Thu, 19 Dec 2013 13:06:26 +0000 Subject: [PATCH] Implement --version flag --- plum/cli/docopt_command.py | 5 ++++- plum/cli/main.py | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/plum/cli/docopt_command.py b/plum/cli/docopt_command.py index 0a11d8eea5..93cf889eb0 100644 --- a/plum/cli/docopt_command.py +++ b/plum/cli/docopt_command.py @@ -12,6 +12,9 @@ def docopt_full_help(docstring, *args, **kwargs): class DocoptCommand(object): + def docopt_options(self): + return {'options_first': True} + def sys_dispatch(self): self.dispatch(sys.argv[1:], None) @@ -22,7 +25,7 @@ class DocoptCommand(object): handler(command_options) def parse(self, argv, global_options): - options = docopt_full_help(getdoc(self), argv, options_first=True) + options = docopt_full_help(getdoc(self), argv, **self.docopt_options()) command = options['COMMAND'] if not hasattr(self, command): diff --git a/plum/cli/main.py b/plum/cli/main.py index 0e94f43871..0e0cb8a538 100644 --- a/plum/cli/main.py +++ b/plum/cli/main.py @@ -1,4 +1,5 @@ import logging +import sys import re from inspect import getdoc @@ -70,6 +71,11 @@ class TopLevelCommand(Command): stop Stop services """ + def docopt_options(self): + options = super(TopLevelCommand, self).docopt_options() + options['version'] = "plum %s" % __version__ + return options + def ps(self, options): """ List services and containers.