Skip to content

cli.py

Command line entrypoint.

This module declares the Plumbum CLI application, its subcommand and options.

CopierApp

The Plumbum CLI application.

Attributes:

Name Type Description
answers_file SwitchAttr

The switch for the answers file option.

extra_paths SwitchAttr

The switch for the extra paths option.

exclude SwitchAttr

The switch for the exclude option.

vcs_ref SwitchAttr

The switch for the VCS ref option.

subdirectory SwitchAttr

The switch for the subdirectory option.

pretend Flag

The flag for the pretend option.

force Flag

The flag for the force option.

skip Flag

The flag for the skip option.

quiet Flag

The flag for the quiet option.

only_diff

The flag for the only diff option.

data_switch(self, values)

Update data with provided values.

Parameters:

Name Type Description Default
values List[str]

The list of values to apply. Each value in the list is of the following form: NAME=VALUE.

required
Source code in copier/cli.py
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
@cli.switch(
    ["-d", "--data"],
    str,
    "VARIABLE=VALUE",
    list=True,
    help="Make VARIABLE available as VALUE when rendering the template",
)
def data_switch(self, values: List[str]) -> None:
    """
    Update data with provided values.

    Arguments:
        values: The list of values to apply.
            Each value in the list is of the following form: `NAME=VALUE`.
    """
    self.data.update(value.split("=", 1) for value in values)  # type: ignore

CopierCopySubApp

The copy subcommand.

CopierUpdateSubApp

The update subcommand.

Attributes:

Name Type Description
only_diff Flag

The flag for the only diff option.

handle_exceptions(method)

Handle keyboard interruption while running a method.

Source code in copier/cli.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def handle_exceptions(method):
    """Handle keyboard interruption while running a method."""

    def _wrapper(*args, **kwargs):
        try:
            try:
                return method(*args, **kwargs)
            except KeyboardInterrupt:
                raise UserMessageError("Execution stopped by user")
        except UserMessageError as error:
            print(colors.red | "\n".join(error.args), file=sys.stderr)
            return 1

    return _wrapper