get_opts
- opthandler.get_opts(argparser, conf_file='hpcssrc.ini', secs_known=None, secs_unknown='sbatch', create_missing_secs=True, ignore_unknown_opts=True, convert=True, **kwargs)[source]
Gather all options from command line and Configuration File.
Gather all options given via the command-line interface and via a config file, merge them and return them in one dictionary.
Options explicitly given via the command-line interface take precedence over options specified in the config file. Options specified in the config file take precedence over default values of the command-line interface.
- Parameters:
argparser (
argparse.ArgumentParser
) – TheArgumentParser
instance that implements the command-line interface. Note: All possible command-line arguments must be contained in theNamespace
, i.e. not-given arguments must not be suppressed withargparse.SUPPRESS
.conf_file (
str
, optional) – The name of the Configuration File.secs_known (
list
ortuple
orstr
orNone
, optional) – Sections of the config file that contain options that can also be specified via the command-line interface (“known” to argparser). IfNone
, use all sections. The options of all known sections will be merged into one sub-dictionary. Options that are given in multiple sections take precedence over each other in reverse order as they appear in secs_known. This means, options in the last given section have the highest preference and options in the first given section have the lowest preference.secs_unknown (
list
ortuple
orstr
orNone
, optional) – Sections of the config file that contain options that cannot be specified via the command-line interface (“unknown” to argparser), but that should still be parsed to the calling script. If you don’t have such sections, set secs_unknown toNone
. The options of all unknown sections will be merged into one sub-dictionary. Options that are given in multiple sections take precedence over each other in reverse order as they appear in secs_unknown (see secs_known).create_missing_secs (
bool
, optional) – IfTrue
, don’t raise an exception if a given section is not contained in the config file but instead create the section (and leave it empty).ignore_unknown_opts (
bool
, optional) – IfTrue
, don’t raise an exception if any option in the given known sections (secs_known) is unknown to argparser, but instead simply ignore it.convert (
bool
, optional) – IfTrue
, applyconvert_str()
to the values of all config-file options and all unknown options. This will convert strings to their corresponding Python data types. IfFalse
, all config-file options and all unknown options will be parsed as strings.kwargs (
dict
, optional) – Keyword arguments to parse toconvert_str()
.
- Returns:
options (
dict
ofdict
) – A dictionary of two dictionaries. The first key (given by the first known section in sections) contains as value a sub-dictionary of all known options and their respective values. The second key (given by sec_unknown) contains as value a dictionary of all unknown options and their respective values.
See also
argparse.ArgumentParser.parse_known_args()
Get known and unknown options from the command-line interface
Notes
- Known options
Options that can also be parsed via the command-line interface (i.e. options that are known to the input
ArgumentParser
).- Unknown options
Options that are not contained in the
Namespace
of the inputArgumentParser
(i.e. options that are unknown to the inputArgumentParser
).