aboutsummaryrefslogtreecommitdiffstats
path: root/poetry_plugin_taskipy/commands.py
blob: 36e06044501c9e580fdbfb2e9258238ed592501d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import pathlib

from cleo.commands.command import Command
from cleo.helpers import argument, option
from taskipy import cli as taskipy_cli


class TaskipyCommand(Command):
    name = "task"
    description = "Run a taskipy task."
    options = [option("list", "l", "Show list of available tasks.")]
    arguments = [
        argument("name", "Name of the task.", optional=True),
        argument(
            "args",
            "Arguments to pass to the task.",
            optional=True,
            multiple=True,
            default=[],
        ),
    ]

    def handle(self) -> int:
        arguments = []

        cwd = pathlib.Path.cwd()
        if self.option("directory"):
            cwd = pathlib.Path(self.option("directory")).resolve()

        if self.option("list"):
            arguments.append("--list")

        if self.argument("name"):
            arguments.append(self.argument("name"))

        if self.argument("args"):
            arguments.extend(self.argument("args"))

        return taskipy_cli.run(arguments, cwd=cwd)