aboutsummaryrefslogtreecommitdiffstats
path: root/task
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2021-03-28 15:32:26 -0500
committerGitHub <noreply@github.com>2021-03-28 23:32:26 +0300
commit40cf72c806f9e05f2a1926848becdaed011b3838 (patch)
tree18f3d897fae8cf0753317d0e7dfb2a82d583e9de /task
parentUpdate README.md (diff)
downloadtaskipy2-40cf72c806f9e05f2a1926848becdaed011b3838.zip
Add usage printout when no task is given (#31)
* Add usage printout when no task is given This addresses issue #30 where 'could not find task "None"' would be outputted when simply `task` is ran without an task name. * Simplify InvalidUsageError's __str__ method * Ignore pyenv's local python version file * Update dependencies in lockfile a.k.a. ran `poetry update` * Disable W0707 in pylint
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