diff options
| author | Roy Sommer <illBeRoy@users.noreply.github.com> | 2022-08-31 22:22:08 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-31 22:22:08 +0300 |
| commit | 62b47b6f081f8b22479dca79c29409cb45319e25 (patch) | |
| tree | 3e1ac9e80985d7df1f66963f57b44f93bb0caffb /task | |
| parent | Release version 1.10.2 (diff) | |
| download | taskipy2-62b47b6f081f8b22479dca79c29409cb45319e25.zip | |
handle listing tasks when there are no tasks (#52)
Diffstat (limited to '')
| -rw-r--r-- | taskipy/exceptions.py | 10 | ||||
| -rw-r--r-- | taskipy/list.py (renamed from taskipy/help.py) | 6 | ||||
| -rw-r--r-- | taskipy/task_runner.py | 4 |
3 files changed, 17 insertions, 3 deletions
diff --git a/taskipy/exceptions.py b/taskipy/exceptions.py index 10eccfa..affdd4e 100644 --- a/taskipy/exceptions.py +++ b/taskipy/exceptions.py @@ -81,6 +81,16 @@ class MissingTaskipyTasksSectionError(TaskipyError): ) +class EmptyTasksSectionError(TaskipyError): + exit_code = 127 + + def __str__(self): + return ( + 'no tasks found. create your first task ' + 'by adding it to your pyproject.toml file under [tool.taskipy.tasks]' + ) + + class CircularVariableError(TaskipyError): exit_code = 127 diff --git a/taskipy/help.py b/taskipy/list.py index 77e3645..50e95aa 100644 --- a/taskipy/help.py +++ b/taskipy/list.py @@ -4,15 +4,19 @@ import colorama # type: ignore from typing import List from taskipy.task import Task +from taskipy.exceptions import EmptyTasksSectionError -class HelpFormatter: +class TasksListFormatter: def __init__(self, tasks: List[Task]): self.__tasks = tasks def print(self, line_width=shutil.get_terminal_size().columns): colorama.init() + if not self.__tasks: + raise EmptyTasksSectionError() + tasks_col = [task.name for task in self.__tasks] longest_item_in_tasks_col = len(max(tasks_col, key=len)) diff --git a/taskipy/task_runner.py b/taskipy/task_runner.py index bf5a3f2..0a72225 100644 --- a/taskipy/task_runner.py +++ b/taskipy/task_runner.py @@ -9,7 +9,7 @@ from typing import Callable, Dict, List, Tuple, Union, Optional import psutil # type: ignore from taskipy.exceptions import CircularVariableError, TaskNotFoundError, MalformedTaskError -from taskipy.help import HelpFormatter +from taskipy.list import TasksListFormatter from taskipy.pyproject import PyProject from taskipy.task import Task from taskipy.variable import Variable @@ -28,7 +28,7 @@ class TaskRunner: def list(self): """lists tasks to stdout""" - formatter = HelpFormatter(self.__project.tasks.values()) + formatter = TasksListFormatter(self.__project.tasks.values()) formatter.print() def run(self, task_name: str, args: List[str]) -> int: |