diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2023-04-22 20:37:20 -0400 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2023-04-22 20:37:20 -0400 |
| commit | 02017dd41fe818d634cf95298cfc782946664240 (patch) | |
| tree | 5b63805e56ed4fced9182b76d801bdd58c5c46e1 | |
| parent | Remove trailing whitespace (diff) | |
| download | taskipy2-02017dd41fe818d634cf95298cfc782946664240.zip | |
Add ability to specify cwd
| -rwxr-xr-x | taskipy/cli.py | 9 |
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() |