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 <filbranden@google.com>
This commit is contained in:
Filipe Brandenburger 2014-08-24 10:50:07 -07:00
parent 84cf497c66
commit 1fe10207b8

View file

@ -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):