From 553c1b0accefe67649f6facb10cfe45143b3cf34 Mon Sep 17 00:00:00 2001 From: Daniel Firth Date: Wed, 30 Nov 2016 14:53:39 +0000 Subject: Use docopt for argument parsing --- requirements.freeze.txt | 1 + requirements.txt | 1 + ybd.py | 19 ++++++++++++++++++- ybd/app.py | 6 ------ 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/requirements.freeze.txt b/requirements.freeze.txt index e3956ac..6d03731 100644 --- a/requirements.freeze.txt +++ b/requirements.freeze.txt @@ -7,3 +7,4 @@ bottle==0.12.1 cherrypy==8.1.2 riemann-client==6.3.0 fs==0.5.0 +docopt==0.6.2 diff --git a/requirements.txt b/requirements.txt index 5e618c1..13ca780 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ bottle cherrypy riemann-client fs +docopt diff --git a/ybd.py b/ybd.py index 933e315..a41bfce 100755 --- a/ybd.py +++ b/ybd.py @@ -13,6 +13,23 @@ # You should have received a copy of the GNU General Public License along # with this program. If not, see . +"""YBD - Yaml Build Deploy Tool + +Usage: + ybd.py + +Options: + -h --help Show this screen. +""" +from docopt import docopt +from ybd.app import config +import os import runpy -runpy.run_module('ybd') + +if __name__ == '__main__': + arguments = docopt(__doc__, version='YBD 16.42') + target = os.path.basename(os.path.splitext(arguments[''])[0]) + config['target'] = target + config['arch'] = arguments[''] + runpy.run_module('ybd') diff --git a/ybd/app.py b/ybd/app.py index 51dc2d9..7aa1e26 100644 --- a/ybd/app.py +++ b/ybd/app.py @@ -131,13 +131,7 @@ def setup(args, original_cwd=""): config['program'] = os.path.basename(args[0]) config['my-version'] = get_version(os.path.dirname(__file__)) log('SETUP', '%s version is' % config['program'], config['my-version']) - if len(args) != 3: - sys.stdout.write("\nUsage: %s DEFINITION_FILE ARCH\n\n" % sys.argv[0]) - sys.exit(1) - log('SETUP', 'Running %s in' % args[0], os.getcwd()) - config['target'] = os.path.basename(os.path.splitext(args[1])[0]) - config['arch'] = args[2] config['sandboxes'] = [] config['overlaps'] = [] config['new-overlaps'] = [] -- cgit v1.2.1