powercli.methods¶
Methods influence the behavior of how flags are parsed.
Module Contents¶
Classes¶
API¶
- class powercli.methods.Method¶
The base class for a method.
- class powercli.methods.Normal¶
Bases:
powercli.methods.MethodThe default way of parsing an argument.
- class powercli.methods.Count¶
Bases:
powercli.methods.MethodCounts the amount of times the flag has been specified.
Examples
from powercli.args import Flag from powercli.methods import Count from powercli.static import Static Flag( short="v", long="verbose", description="Enables verbosity up to 4 different levels" method=Count( lambda _, amount: amount in range(0, 5), # restrict range default=Static(2) # returned when absent ) )
Requirements
The flag does not take any values.
The flag does not have any default values.
- validate_amount: collections.abc.Callable[[powercli.typedefs.Context[powercli.methods.Count.FV, powercli.methods.Count.PV], int], bool | str]¶
‘Static(…)’
- class powercli.methods.Repeat¶
Bases:
powercli.methods.MethodAllows multiple presence of the flag.
The returned [powercli.parser.ParsedFlag] contains its converted values within a list even if the flag does not take any values.
Examples
from pathlib import Path from powercli.args import Flag from powercli.methods import Repeat Flag( short="W", long="warning", description="Displays warning messages", method=Repeat() values=[("PATH", Path)] )
Requirements
The flag does not take any default values.
- validate_amount: collections.abc.Callable[[powercli.typedefs.Context[powercli.methods.Repeat.FV, powercli.methods.Repeat.PV], int], bool | str]¶
‘Static(…)’
A function that validates the amount of repetitions.
- class powercli.methods.Switch¶
Bases:
powercli.methods.MethodEvaluates
Pwhen the value is present orAfor absence.Parameters
on_presence- The value evaluated when the flag is present.on_absence- The value evaluated when the flag is absent.
Examples
from powercli.args import Flag from powercli.methods import Switch from powercli.utils import static Flag( short="r", description="Walks the directory recursively", method=Switch.boolean() )
Requirements
The flag does not take any values.
The flag does not take any default values.
- on_presence: powercli.typedefs.WithContext[powercli.methods.Switch.FV, powercli.methods.Switch.PV, powercli.methods.Switch.P]¶
None
The value evaluated when the flag is present.
- on_absence: powercli.typedefs.WithContext[powercli.methods.Switch.FV, powercli.methods.Switch.PV, powercli.methods.Switch.A]¶
None
The value evaluated when the flag is absent.