xoa.cfgm.ConfigManager.arg_parse
- ConfigManager.arg_parse(parser=None, exc=[], parse=True, args=None, getparser=False, getargs=False, cfgfile='config.cfg', patch=None, cfgfileopt='--cfgfile', cfgfilepatch='before', nested=None, extraopts=None)[source]
Commandline options (
argparse
) and config mixer.Creates command-line options from config defaults
Parse command-line argument and create a configuration patch
For instance, the following config define the commandline option
--section1-my-section2-my-key
withvalue
as a default value, stored in a special group of options with a short name and a long description:[section1] # Short name : long description of the group [[my_section2]] my_key=value
Warning
Section and option names must not contain any space-like character !
Note
If you want to prevent conflict of options, don’t use
"_"
in section and option names.- Parameters:
parser –
- optional, a default one is created if not given. This can be:
a
OptionParser
instancea
dict
with keyword arguments for the one to be created
exc (optional, list) – List of keys to be excluded from parsing.
parse (optional, bool) – If
True
, parse commande line options and argumentsargs (optional) – List of arguments to parse instead of default sys.argv[1:]
getparser (optional, bool) – Allow getting the parser in addition to the config if parse=True
getargs (optional, bool) – allow getting the parsed arguments in addition to the config if parse=True
patch (optional) –
Used if parse is True. Can take the following values:
a
bool
value indicating wheter to apply defaults on the returned config before applying the command line configa
ConfigObj
instance to apply on the returned config before applying the command line config
cfgfileopt (optional) – If present a config file option will be added. Can be a
string
or couple of strings to use as the option short and/or long namecfgfilepatch –
specify if the returned config must be patched if a config file command line option is provided and when to patch it. Can take the following values:
True or ‘before’: the config file would be used before command line options
’after’: the config file would be used after command line options
Any False like value: the config file would not be used
nested (str) – Name of a section whose defines the configuration. It must be used when the configuration in nested in more g eneral configuration.
extraopts (dict) – Extra options to declare in the form
[(args1, kwargs1), ((args2, kwargs2), ...]
- Returns:
OptionParser
– if parse is FalseConfigObj
– if parse is True and getparser is not True(
ConfigObj
,OptionParser
) – if both parse and getparser are True