From a66782064e950d417b9e5bd18c2d402e7cff67a1 Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Thu, 2 Feb 2023 16:42:16 +0100 Subject: [PATCH] ZH: scriptlib nicer myargumentparser --- .../airshower_beacon_simulation/scriptlib.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/simulations/airshower_beacon_simulation/scriptlib.py b/simulations/airshower_beacon_simulation/scriptlib.py index 165f32f..0edc5d6 100644 --- a/simulations/airshower_beacon_simulation/scriptlib.py +++ b/simulations/airshower_beacon_simulation/scriptlib.py @@ -4,9 +4,13 @@ Some preconfigured ArgumentParser from argparse import ArgumentParser -def MyArgumentParser(default_fig_dir='./figures', default_show_plots=False, **kwargs): +def MyArgumentParser( + default_fig_dir='./figures', + default_show_plots=False, + **kwargs): """ - A somewhat preconfigured ArgumentParser + A somewhat preconfigured ArgumentParser to be shared across + multiple scripts. Set show_plots=True to by default enable showing plots. Likewise, set fig_dir=None to by default disable saving figures. @@ -14,11 +18,11 @@ def MyArgumentParser(default_fig_dir='./figures', default_show_plots=False, **kw parser = ArgumentParser(**kwargs) # Whether to show plots - parser.add_argument('--show-plots', action='store_true') - parser.add_argument('--no-show-plots', dest='show-plots', action='store_false') - parser.set_defaults(show_plots=default_show_plots) + group1 = parser.add_mutually_exclusive_group(required=False) + group1.add_argument('--show-plots', action='store_true', default=default_show_plots, help='Default: %(default)s') + group1.add_argument('--no-show-plots', dest='show-plots', action='store_false') # Figures directory - parser.add_argument('--fig-dir', type=str, default=default_fig_dir) + parser.add_argument('--fig-dir', type=str, default=default_fig_dir, help='Set None to disable saving figures. (Default: %(default)s)') return parser