-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes: #119
- Loading branch information
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
codecov: | ||
require_ci_to_pass: true | ||
comment: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import json | ||
import logging | ||
import os | ||
import shutil | ||
import sys | ||
from typing import List, Optional | ||
|
||
from mk.exec import run_or_fail | ||
from mk.tools import Action, Tool | ||
|
||
|
||
class TaskfileTool(Tool): | ||
name = "taskfile" | ||
|
||
def __init__(self, path=".") -> None: | ||
"""Initialize.""" | ||
super().__init__(path) | ||
self.executable = "" | ||
|
||
def is_present(self, path: str) -> bool: | ||
if os.path.isfile(os.path.join(path, "taskfile.yml")): | ||
# On some Linux distros might be exposed as taskfile in order to | ||
# avoid clashing with the other Task Warrior executable https://taskwarrior.org/ | ||
self.executable = shutil.which("taskfile") or shutil.which("task") | ||
if not self.executable: | ||
logging.error( | ||
"taskfile.yml config found but the tool is not installed. See https://taskfile.dev/installation/" | ||
) | ||
sys.exit(1) | ||
return True | ||
return False | ||
|
||
def actions(self) -> List[Action]: | ||
actions: List[Action] = [] | ||
tasks_json = ( | ||
run_or_fail( | ||
["task", "--list", "--json"], | ||
tee=False, | ||
).stdout | ||
or "" | ||
) | ||
for task in json.loads(tasks_json)["tasks"]: | ||
desc = task["desc"] | ||
if task["summary"]: | ||
desc += "\n" | ||
desc += task["summary"] | ||
actions.append( | ||
Action( | ||
name=task["name"], | ||
tool=self, | ||
description=desc, | ||
args=[task["name"]], | ||
) | ||
) | ||
return actions | ||
|
||
def run(self, action: Optional[Action] = None) -> None: | ||
if not action: | ||
cmd = ["task"] | ||
else: | ||
cmd = ["task", action.name] | ||
run_or_fail(cmd, tee=True) |