mirror of
https://gitlab.science.ru.nl/mthesis-edeboone/m-thesis-introduction.git
synced 2024-12-22 11:33:32 +01:00
ZH: scriptlib nicer myargumentparser
This commit is contained in:
parent
ad7a62604b
commit
a66782064e
1 changed files with 10 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue