powercli.utils

Utilities related to commands and arguments.

Module Contents

Classes

ArgIterator

An iterator over raw arguments.

Functions

static

Returns a callable which depends the provided value ignoring the supplied arguments.

member_of

Creates a converter for an enum type.

one_of

Modifies each flag to only be allowed when all other flags are absent.

API

powercli.utils.static(value: powercli.utils.static.T, /) powercli.static.Static[powercli.utils.static.T]

Returns a callable which depends the provided value ignoring the supplied arguments.

Deprecated since version 0.2.0: Deprecated in favor of powercli.static.Static.

Examples

from powercli import Flag

Flag(
    # ...
    required=static(True)
)
powercli.utils.member_of(enum: type[enum.StrEnum], *, ignore_case: bool = True) powercli.typedefs.Converter[str]

Creates a converter for an enum type.

Parameters

  • enum - The enum type with the members’ values being the possible values.

  • ignore_case - Ignore case when finding enum member.

powercli.utils.one_of(*flags: powercli.args.Flag[powercli.utils.one_of.FV, powercli.utils.one_of.PV, powercli.utils.one_of.FV], required: powercli.typedefs.WithContext[powercli.utils.one_of.FV, powercli.utils.one_of.PV, bool] = Static(False)) collections.abc.Iterable[powercli.args.Flag[powercli.utils.one_of.FV, powercli.utils.one_of.PV, powercli.utils.one_of.FV]]

Modifies each flag to only be allowed when all other flags are absent.

Parameters

  • required - Whether any of the flags is required.

class powercli.utils.ArgIterator

Bases: collections.abc.Iterator[str]

An iterator over raw arguments.

prepend(value: str) None

Prepends the iterator with a value.

This makes it possible to peek the iterator.