powercli.command

The heart of PowerCLI - the command class.

Module Contents

Classes

Example

An example describing the usage of a command.

Command

A command which might contains arguments and subcommands.

API

class powercli.command.Example

An example describing the usage of a command.

args: collections.abc.Collection[str]

None

The arguments of the command.

This should not contain the name of any parent commands or the command itself.

description: str | None

None

A one-sentence describing what the example does.

class powercli.command.Command

A command which might contains arguments and subcommands.

Parameters

  • name - Sets the name of the command.

    Defaults to the first argument provided in the command-line (sys.argv[0]).

  • aliases - A set of aliases this command can be invoked with as well.

    Note

    This only applies for subcommands.

  • hidden_aliases - Same as aliases but not shown in help messages.

  • description - A short description of the command.

  • long_description - A concise description of the command.

  • epilog - Additional text displayed at the bottom.

  • prefix_short - The prefix used to specify flags by their short name.

    Most command-line programs use dashes (-) for flags. This is the default and can be explicitly specified as shown below.

    from powercli import Command
    
    Command(
        # ...
        prefix_short="-",
        prefix_long="--",
    )
    

    On Windows, command-line programs commonly use slashes (/) for flags. Each flag needs to be prefixed separately which means flags with both short and long names cannot be registered.

    from powercli import Command
    
    Command(
        # ...
        prefix_long="/",
    )
    
  • prefix_long - The prefix used to specify flags by their long name.

    See also

    prefix_short

  • category - An optional category used for grouping commands.

  • deprecation - Whether this command is deprecated.

  • file - The file used for commands or arguments that display text.

  • add_common_flags - Adds h, help, list and version flags.

    This only has an effect when a prefix is defined for the command.

  • add_common_subcommands - Adds help, list, version subcommands.

name: str

‘Factory(…)’

The name of the command.

aliases: set[str]

‘Factory(…)’

A set of aliases this command can be invoked with if it’s a subcommand.

hidden_aliases: set[str]

‘Factory(…)’

A set of hidden aliases this command can be invoked with if it’s a subcommand.

description: str | None

None

A short one-sentence description of this command.

long_description: str | None

None

A long multi-sentence description of this command.

epilog: str | None

None

Additional text displayed at the bottom.

prefix_short: str | None

‘-’

The prefix this command uses for short flag names.

prefix_long: str | None

‘–’

The prefix this command uses for long flag names.

category: powercli.category.Category | None

None

The optional category of this command.

deprecation: powercli.deprecation.Deprecation | bool | None

None

Whether this command is deprecated.

examples: collections.abc.Collection[powercli.command.Example]

‘Factory(…)’

A collection of examples describing the usage of this command.

file: TextIO

‘Factory(…)’

The stream this command writes text to.

property parent: powercli.command.Command[FV, PV] | None

Returns the parent command.

parents() collections.abc.Generator[powercli.command.Command[FV, PV], None, None]

Yields each parent command.

names() collections.abc.Generator[str, None, None]

Yields all names this command can be invoked with.

has_prefix() bool

Returns True when either a short or long prefix is specified for this command.

has_prefix_short() bool

Returns True when a short prefix is specified for this command.

has_prefix_long() bool

Returns True when a long prefix is specified for this command.

has_positional() bool

Returns True when a positional is registered.

has_variadic_positional() bool

Returns True when a variadic positional is registered.

has_flag() bool

Returns True when a flag is registered.

has_subcommand() bool

Returns True when a subcommand is registered.

add_arg(arg: powercli.args.Argument, /) powercli.command.Command[FV, PV]

Registers an argument to the command.

add_args(args: collections.abc.Iterable[powercli.args.Argument], /) powercli.command.Command[FV, PV]

Registers multiple arguments to the command.

add_subcommand(cmd: powercli.command.Command[FV, PV], /) powercli.command.Command[FV, PV]

Registers a subcommand to the command.

flag(*args: Any, **kwargs: Any) powercli.command.Command[FV, PV]

Creates and registers a flag to the command.

pos(*args: Any, **kwargs: Any) powercli.command.Command[FV, PV]

Creates and registers a positional to the command.

vpos(*args: Any, **kwargs: Any) powercli.command.Command[FV, PV]

Creates and registers a variadic positional to the command.

parse_args(args: list[str] | None = None) powercli.parser.ParsedCommand[FV, PV]

Parses arguments from args, or, if None from argv.