aboutsummaryrefslogtreecommitdiffstats
path: root/task
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xtaskipy/cli.py6
-rw-r--r--taskipy/exceptions.py11
2 files changed, 16 insertions, 1 deletions
diff --git a/taskipy/cli.py b/taskipy/cli.py
index 97d8174..67baa0c 100755
--- a/taskipy/cli.py
+++ b/taskipy/cli.py
@@ -3,7 +3,7 @@ import argparse
import sys
from pathlib import Path
-from taskipy.exceptions import TaskipyError
+from taskipy.exceptions import TaskipyError, InvalidUsageError
from taskipy.task_runner import TaskRunner
@@ -16,6 +16,7 @@ def main():
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:
runner = TaskRunner(Path.cwd())
@@ -23,6 +24,9 @@ def main():
runner.list()
sys.exit(0)
+ if args.name is None:
+ raise InvalidUsageError(parser)
+
exit_code = runner.run(args.name, args.args)
sys.exit(exit_code)
except TaskipyError as e:
diff --git a/taskipy/exceptions.py b/taskipy/exceptions.py
index b171231..16d1e58 100644
--- a/taskipy/exceptions.py
+++ b/taskipy/exceptions.py
@@ -1,3 +1,5 @@
+from argparse import ArgumentParser
+
class TaskipyError(Exception):
exit_code = 1
@@ -30,6 +32,15 @@ class TaskNotFoundError(TaskipyError):
def __str__(self):
return f'could not find task "{self.task}"'
+class InvalidUsageError(TaskipyError):
+ exit_code = 127
+
+ def __init__(self, parser: ArgumentParser):
+ super().__init__()
+ self.__parser = parser
+
+ def __str__(self):
+ return self.__parser.format_usage().strip('\n')
class MissingTaskipySettingsSectionError(TaskipyError):
exit_code = 127