From 5ca029174910cc7e412533b2e087c056b82a7be1 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sun, 17 Dec 2023 16:09:12 +0800 Subject: [PATCH] Minor changes --- esds/__main__.py | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/esds/__main__.py b/esds/__main__.py index a79b78e..ccbad20 100644 --- a/esds/__main__.py +++ b/esds/__main__.py @@ -2,31 +2,29 @@ import sys, argparse, os from .platform import YAMLPlatformFile from esds import __version__ -def run(arguments): - parser = argparse.ArgumentParser(description='Run a simulation') - parser.add_argument("platform", help="Run a simulation using a specific platform file") - args = parser.parse_args(arguments[1:]) - if args.platform: - simulation=YAMLPlatformFile(args.platform) - # Allow importlib (in simulator.run()) to import file from the platform.yaml directory - sys.path.insert(0, simulation.location) - simulation.run() - else: - parser.print_help() +def run(platform): + simulation=YAMLPlatformFile(platform) + # Allow importlib (in simulator.run()) to import file from the platform.yaml directory + sys.path.insert(0, simulation.location) + simulation.run() def main(): - ##### Parse arguments + ##### Main parser parser = argparse.ArgumentParser( description='ESDS simulator command line interface. Run simulations and perform various simulation tasks.', formatter_class=argparse.RawTextHelpFormatter) - parser.add_argument("command", help="Execute the specified command.\nAvailable commands are: run", nargs=argparse.REMAINDER) parser.add_argument("--version", help="Show esds version", action="store_true") - args = parser.parse_args() + subparsers = parser.add_subparsers(dest="command", help='Execute the specified command') - ##### Run commands + ##### Run subparser + run_parser=subparsers.add_parser("run", description='Run a simulation') + run_parser=run_parser.add_argument("platform", help="Platform file") + + ##### Execute commands + args = parser.parse_args() if args.command: - if args.command[0] == "run": - run(args.command) + if args.command == "run": + run(args.platform) elif args.version: print("ESDS v"+__version__) else: