From 1fe10207b8f13f6eb0805a756184cf6a2fb5639e Mon Sep 17 00:00:00 2001 From: Filipe Brandenburger Date: Sun, 24 Aug 2014 10:50:07 -0700 Subject: [PATCH] Check the value of the --color argument Make sure it's either `auto' (the default), `always' or `never'. If it does not match any of the values, raise a Docopt exception that causes it to print usage and exit. Tested: - $ sudo ./bootstrap-vz --color=invalid manifests/gce.manifest.yml Value of --color must be one of auto, always or never. Usage: bootstrap-vz [options] MANIFEST Signed-off-by: Filipe Brandenburger --- bootstrapvz/base/main.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bootstrapvz/base/main.py b/bootstrapvz/base/main.py index 227f5b9..7e1c054 100644 --- a/bootstrapvz/base/main.py +++ b/bootstrapvz/base/main.py @@ -34,7 +34,7 @@ def main(): def get_opts(): """Creates an argument parser and returns the arguments it has parsed """ - from docopt import docopt + import docopt usage = """bootstrap-vz Usage: bootstrap-vz [options] MANIFEST @@ -49,7 +49,10 @@ Options: --debug Print debugging information -h, --help show this help """ - return docopt(usage) + opts = docopt.docopt(usage) + if opts['--color'] not in ('auto', 'always', 'never'): + raise docopt.DocoptExit('Value of --color must be one of auto, always or never.') + return opts def setup_loggers(opts):