From a42bc68998951d6c5b3fcfe71eed42eb2eb7a4f3 Mon Sep 17 00:00:00 2001 From: Arthur 'Grizzly' Grisel-Davy Date: Mon, 3 May 2021 12:06:07 +0200 Subject: [PATCH] Add arguments --- jumpstart.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/jumpstart.py b/jumpstart.py index 0b6ffc5..ecc4262 100644 --- a/jumpstart.py +++ b/jumpstart.py @@ -3,6 +3,9 @@ import subprocess import json +import argparse + +# TODO catch errors in parameters def get_command(options): command = 'tilix' @@ -54,17 +57,26 @@ def get_command(options): return(command) if __name__ == "__main__": - templates_dir = './templates/' - params_path = './params.json' - template = 'eet2.json' + + parser = argparse.ArgumentParser() + parser.add_argument("template",help="Specify the templato to use (must be in ./templates).") + parser.add_argument("-t","--templates_dir", help="Specify the template directory (absolute path)") + parser.add_argument("-p","--parameters", help="Specify the parameters file (default to ./params.json)") + parser.add_argument("-v", "--verbose", help="Activate verbose output", action="store_true") + args = parser.parse_args() + + templates_dir = args.templates_dir or "./templates/" + params_path = args.parameters or "./params.json" + + template = args.template + ".json" + verbose = args.verbose with open(templates_dir+template,'r') as f: options = json.loads(f.read()) for fen in options['fenetres']: - print(fen) - print("Lancement de {}:".format(fen['name'])) + if verbose:print("Lancement de {}:".format(fen['name'])) command = get_command(fen) - print("Using command: \n{}".format(command)) + if verbose:print("Using command: \n{}".format(command)) subprocess.call(command.split(' '))