powercli.args¶
Argument classes that can be used to create flags and positionals.
Module Contents¶
Classes¶
Base class for arguments. |
|
A flag is usually an optional option that toggles some feature. |
|
A positional is usually a required value of a command. |
|
A positional that accepts a variadic amount of values. |
API¶
- class powercli.args.Argument¶
Base class for arguments.
You should not subclass this class as the parser only knows how to handle
powercli.args.Flags andpowercli.args.Positionals. Create a subclass of either of those.- identifier: powercli.typedefs.Identifier¶
‘field(…)’
A unique identifier which can be used for queries and validation.
Defaults to the ID of the created instance.
- dependencies: set[powercli.typedefs.Identifier]¶
‘Factory(…)’
Argument this argument depends on at parse time.
This must be a set of all argument IDs that are required to evaluated the default value and for flags whether it is required. Arguments needed to evaluate whether a flag is allowed are not dependencies.
- class powercli.args.Flag¶
Bases:
powercli.args.ArgumentA flag is usually an optional option that toggles some feature.
Flags can also accept values, be repeated and much more.
‘Factory(…)’
A set of hidden aliases for the short name.
‘Factory(…)’
A set of hidden aliases for the long name.
- values: collections.abc.Sequence[tuple[str, powercli.typedefs.Converter[powercli.args.Flag.T]] | types.EllipsisType]¶
‘Factory(…)’
Values the flag takes.
Examples
from powercli import Flag Flag( # ... values=[("X", float), ..., ("Y", int), ...], # parse as much `float`s as possible, then as much `int`s as possible )
Tip
Avoid using a flag that accepts a variable amount of string or something similar as it consumes potential flags as well. For example:
from powercli import Flag Flag( # ... short="f", values=[("X", str), ...], # parse as much `float`s as possible )
If we add this flag to a command and input something like
-f --hey --ho, then--heyand--howill be parsed as values of the flag-finstead of separate flags--heyand--ho.This may be useful however if you want to consume all arguments without parsing them for example when passing them to an external program. Usually such flag has an empty long name and no short name:
from powercli import Flag Flag( # ... short=None, long="", values=[("ARGS", str), ...], )
- default: powercli.typedefs.WithContext[powercli.args.Flag.FV, powercli.args.Flag.PV, collections.abc.Collection[powercli.args.Flag.T]] | None¶
None
Default values for the flag.
Examples
from powercli import Flag, Static Flag( # ... values=[("X", float), ("Y", int)], default=Static([1.5, 42]), )
- method: powercli.methods.Method¶
‘Factory(…)’
The method of the flag that influences the parsing behavior.
- required: powercli.typedefs.WithContext[powercli.args.Flag.FV, powercli.args.Flag.PV, bool | str]¶
‘Static(…)’
Whether the flag is required.
- allowed: powercli.typedefs.WithContext[powercli.args.Flag.FV, powercli.args.Flag.PV, bool | str]¶
‘Static(…)’
Whether the flag is allowed.
- deprecation: powercli.typedefs.WithContext[powercli.args.Flag.FV, powercli.args.Flag.PV, bool | powercli.deprecation.Deprecation | None]¶
‘Static(…)’
Whether the flag is deprecated.
The flag should not be considered deprecated when
requiredevaluatesTrue. When the user makes use of a flag that is considered deprecated aDeprecationWarningwill be emitted.Examples
from powercli import Flag Flag( identifier="f", # ... deprecation=lambda ctx: Deprecation("using flag f when flag g is 1 is deprecated") if ctx.value_of("g") == [1] else None )
- category: powercli.category.Category | None¶
None
The optional category of this flag.
- names() collections.abc.Generator[str, None, None]¶
Yields all names this flag can be specified with.
- visible_short_names() collections.abc.Generator[str, None, None]¶
Yields all non-hidden short names this flag can be specified with.
- visible_long_names() collections.abc.Generator[str, None, None]¶
Yields all non-hidden long names this flag can be specified with.
- class powercli.args.Positional¶
Bases:
powercli.args.ArgumentA positional is usually a required value of a command.
Positionals cannot be mixed with subcommands.
- into: powercli.typedefs.Converter[powercli.args.Positional.T] | powercli.typedefs.Converter[str]¶
None
A function that converts the input.
- class powercli.args.VariadicPositional¶
Bases:
powercli.args.Positional[powercli.args.VariadicPositional.FV,powercli.args.VariadicPositional.PV,powercli.args.VariadicPositional.T]A positional that accepts a variadic amount of values.
Positionals cannot be mixed with subcommands.