aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2023-04-22 20:37:20 -0400
committerEugene Triguba <eugenetriguba@gmail.com>2023-04-22 20:37:20 -0400
commit02017dd41fe818d634cf95298cfc782946664240 (patch)
tree5b63805e56ed4fced9182b76d801bdd58c5c46e1
parentRemove trailing whitespace (diff)
downloadtaskipy2-02017dd41fe818d634cf95298cfc782946664240.zip
Add ability to specify cwd
-rwxr-xr-xtaskipy/cli.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/taskipy/cli.py b/taskipy/cli.py
index 54b25cd..204880e 100755
--- a/taskipy/cli.py
+++ b/taskipy/cli.py
@@ -2,7 +2,7 @@
import argparse
import sys
from pathlib import Path
-from typing import List
+from typing import List, Union
from taskipy.exceptions import TaskipyError, InvalidUsageError
from taskipy.task_runner import TaskRunner
@@ -13,11 +13,13 @@ def main():
sys.exit(exit_code)
-def run(args: List[str]) -> int:
+def run(args: List[str], cwd: Union[str, Path, None] = None) -> int:
"""Run the taskipy CLI programmatically.
Args:
args: The arguments passed to the taskipy CLI.
+ cwd: The working directory to run the task in. If not
+ provided, defaults to the current working directory.
Returns:
0 on success; > 0 for an error.
@@ -32,7 +34,8 @@ def run(args: List[str]) -> int:
parsed_args = parser.parse_args(args=args)
try:
- runner = TaskRunner(Path.cwd())
+ cwd = Path(cwd).resolve() if cwd is not None else Path.cwd()
+ runner = TaskRunner(cwd)
if parsed_args.list:
runner.list()