diff options
| author | Bernardas AliĊĦauskas <bernardas.alisauskas@pm.me> | 2020-10-07 15:37:44 +0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-07 11:37:44 +0300 |
| commit | ff080abe550af90a8445332058434743ee7529c7 (patch) | |
| tree | 1ddc301d4751f1a52ee5dbabff5d1d27cd58ed4e /task | |
| parent | Release version 1.3.0 (diff) | |
| download | taskipy2-ff080abe550af90a8445332058434743ee7529c7.zip | |
add list command which lists tasks (#21)
* add list command which lists tasks
* refactor list argument as a flag
add tests and readme for --list flag
* more tests
* Update tests/test_taskipy.py
Co-authored-by: Roy Sommer <illBeRoy@users.noreply.github.com>
* refactor listing to taskrunner
fix tests and cli to handle --list following arguments cases
Co-authored-by: Roy Sommer <illBeRoy@users.noreply.github.com>
Diffstat (limited to '')
| -rwxr-xr-x | taskipy/cli.py | 14 | ||||
| -rw-r--r-- | taskipy/task_runner.py | 10 |
2 files changed, 16 insertions, 8 deletions
diff --git a/taskipy/cli.py b/taskipy/cli.py index 06acd6c..d558e3b 100755 --- a/taskipy/cli.py +++ b/taskipy/cli.py @@ -12,14 +12,16 @@ def main(): prog='task', description='runs a task specified in your pyproject.toml under [tool.taskipy.tasks]', ) - parser.add_argument('name', help='name of the task') - parser.add_argument( - 'args', nargs=argparse.REMAINDER, help='arguments to pass to the task' - ) + parser.add_argument('--list', help='show list of available tasks', action='store_true') + parser.add_argument('name', help='name of the task', nargs='?') + parser.add_argument('args', nargs=argparse.REMAINDER, help='arguments to pass to the task') args = parser.parse_args() - try: - exit_code = TaskRunner(Path.cwd() / 'pyproject.toml').run(args.name, args.args) + runner = TaskRunner(Path.cwd() / 'pyproject.toml') + if args.list: + runner.list() + sys.exit(0) + exit_code = runner.run(args.name, args.args) sys.exit(exit_code) except TaskipyError as e: print(e) diff --git a/taskipy/task_runner.py b/taskipy/task_runner.py index 4c126dc..5c16da1 100644 --- a/taskipy/task_runner.py +++ b/taskipy/task_runner.py @@ -13,10 +13,16 @@ from taskipy.task import Task class TaskRunner: def __init__(self, pyproject_path: Union[str, Path]): self.__pyproject_path = pyproject_path - self.__project = PyProject(pyproject_path) + self.project = PyProject(pyproject_path) + + def list(self): + """lists tasks to stdout""" + longest = len(max(self.project.tasks, key=len)) + for k, v in self.project.tasks.items(): + print(f'{k:<{longest}} {v}') def run(self, task_name: str, args: List[str]) -> int: - task = Task(task_name, args, self.__project) + task = Task(task_name, args, self.project) for command in task.commands: if task.runner is not None: |