Param
Param¶
- class Param[source]¶
Bases:
configpile.arg.Arg
,Generic
[configpile.arg._Value_co
]Describes an argument holding a value of a given type
You’ll want to construct parameters using the static methods available:
store()
to create a parameter that keeps the last value providedappend()
to create a parameter that collects all the provided values into a sequence. Note that the parsed value must already be a sequence.append1()
to create a parameter that collects all the provided value into a sequence. The parsed value should not be a sequence.
For the constructions above, you can construct positional parameters by setting the
Param.positional
field.config()
returns a parameter that parses configuration files.
Attributes
Note: attributes inherited from parent classes are not shown here, if any
Argument type, parser from string to value
Whether this represents a list of config files
Whether this represents a root path
Argument collector
Default value inserted as instance
Python identifier representing the argument
Whether this parameter can appear as a positional parameter and how
Configuration key name used in INI files
Environment variable name
Methods
Returns a sequence of all forms of command line options
Returns a sequence of all forms of command line options
Returns a sequence of all forms of command line flags
Returns a newly created argument that joins parsed sequences of values
Returns a newly created argument that appends single parsed values
Returns the keyword arguments for use with argparse.ArgumentParser.add_argument
Creates a parameter that parses configuration files and stores their names
Returns whether the argument is required
Creates a parameter that describes a root path
Creates a parameter that stores the last provided value
Returns updated values for this argument, used during
App
constructionUpdates a config processor with the processing required by this argument
Returns a copy of this argument with some data updated from its declaration context
List of members of Param
- parser: configpile.parsers.Parser[configpile.arg._Value_co]¶
Argument type, parser from string to value
- collector: configpile.collector.Collector[configpile.arg._Value_co]¶
Argument collector
- positional: Optional[configpile.enums.Positional]¶
Whether this parameter can appear as a positional parameter and how
A positional parameter is a parameter that appears without a preceding flag
- config_key_name: Optional[Union[str, configpile.enums.Derived]]¶
Configuration key name used in INI files
It is lowercase, and words are separated by hyphens.
- env_var_name: Optional[Union[str, configpile.enums.Derived]]¶
Environment variable name
The environment variable name has a prefix, followed by the Python identifier in uppercase, with underscore as separator.
This prefix is provided by
App.env_prefix_
- update_dict_(name, help, env_prefix)[source]¶
Returns updated values for this argument, used during
App
construction- Parameters
Returns:
- argparse_argument_kwargs()[source]¶
Returns the keyword arguments for use with argparse.ArgumentParser.add_argument
- update_processor(pf)[source]¶
Updates a config processor with the processing required by this argument
- Parameters
pf (
ProcessorFactory
[TypeVar
(_Config
, bound=Config
)]) – Processor factory- Return type
- static store(parser, *, help=None, default_value=None, positional=None, short_flag_name=None, long_flag_name=Derived.KEBAB_CASE, config_key_name=Derived.KEBAB_CASE, env_var_name=None)[source]¶
Creates a parameter that stores the last provided value
If a default value is provided, the argument can be omitted. However, if the default_value
None
is given (default), then the parameter cannot be omitted.- Parameters
parser (
Parser
[TypeVar
(_Value_co
, covariant=True)]) – Parser that transforms a string into a value- Keyword Arguments
help – Help description (autodoc/docstring is used otherwise)
default_value – Default value
positional – Whether this parameter is present in positional arguments
short_flag_name –
long_flag_name – Long option name (auto. derived from fieldname by default)
config_key_name – Config key name (auto. derived from fieldname by default)
env_var_name – Environment variable name (forbidden by default)
- Return type
- Returns
The constructed Param instance
- static root_path(*, help=None, short_flag_name=None, long_flag_name=Derived.KEBAB_CASE, env_var_name=None)[source]¶
Creates a parameter that describes a root path
- Keyword Arguments
help – Help description (autodoc/docstring is used otherwise)
short_flag_name – Short option name (optional)
long_flag_name – Long option name (auto. derived from fieldname by default)
env_var_name – Environment variable name (forbidden by default)
- Return type
- Returns
A root path parameter
- static config(*, help=None, short_flag_name=None, long_flag_name=Derived.KEBAB_CASE, env_var_name=None)[source]¶
Creates a parameter that parses configuration files and stores their names
- Keyword Arguments
help – Help description (autodoc/docstring is used otherwise)
short_flag_name – Short option name (optional)
long_flag_name – Long option name (auto. derived from fieldname by default)
env_var_name – Environment variable name (forbidden by default)
- Return type
- Returns
A configuration files parameter
- static append1(parser, *, help=None, positional=None, short_flag_name=None, long_flag_name=Derived.KEBAB_CASE, config_key_name=Derived.KEBAB_CASE, env_var_name=None)[source]¶
Returns a newly created argument that appends single parsed values
While
append()
creates a parameter that joins sequences of values, this method creates a parameter that appends single items to a sequence.- Parameters
parser (
Parser
[TypeVar
(_Item_co
, covariant=True)]) – Parser that transforms a string into a single value item- Keyword Arguments
help – Help description (autodoc/docstring is used otherwise)
positional – Whether this argument is present in positional arguments
short_flag_name – Short option name (optional)
long_flag_name – Long option name (auto. derived from fieldname by default)
config_key_name – Config key name (auto. derived from fieldname by default)
env_var_name – Environment variable name (forbidden by default)
- Return type
- static append(parser, *, help=None, positional=None, short_flag_name=None, long_flag_name=Derived.KEBAB_CASE, config_key_name=Derived.KEBAB_CASE, env_var_name=None)[source]¶
Returns a newly created argument that joins parsed sequences of values
- Parameters
parser (
Parser
[Sequence
[TypeVar
(_Item_co
, covariant=True)]]) – Parser that transforms a string into a sequence of values- Keyword Arguments
help – Help description (autodoc/docstring is used otherwise)
positional – Whether this argument is present in positional arguments
short_flag_name – Short option name (optional)
long_flag_name – Long option name (auto. derived from fieldname by default)
config_key_name – Config key name (auto. derived from fieldname by default)
env_var_name – Environment variable name (forbidden by default)
- Return type
- __init__(help, short_flag_name, long_flag_name, parser, is_config, is_root_path, collector, default_value, name, positional, config_key_name, env_var_name)¶
- static __new__(cls, *args, **kwds)¶
- updated(name, help, env_prefix)¶
Returns a copy of this argument with some data updated from its declaration context
- short_flag_name: Optional[str]¶
Short option name, used in command line parsing, prefixed by a single hyphen
- long_flag_name: Optional[Union[str, configpile.enums.Derived]]¶
Long option name used in command line argument parsing
It is in general lowercase, prefixed with
--
and words are separated by hyphens.,If set to