Skip to content

Commit 7d19b05

Browse files
committed
app: poe task runner
1 parent 1d531d6 commit 7d19b05

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

src/runners/poe.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
use crate::command_utils::run_command;
2+
use crate::common::pyproject::PyProjectToml;
3+
use crate::common::pyproject_toml_has_tool;
4+
use crate::errors::KeeperError;
5+
use crate::models::Task;
6+
use crate::task;
7+
use error_stack::Result;
8+
use std::process::Output;
9+
use which::which;
10+
11+
pub fn is_available() -> bool {
12+
std::env::current_dir()
13+
.map(|dir| pyproject_toml_has_tool("poe"))
14+
.unwrap_or(false)
15+
}
16+
17+
pub fn is_command_available() -> bool {
18+
which("poe").is_ok()
19+
}
20+
21+
pub fn list_tasks() -> Result<Vec<Task>, KeeperError> {
22+
let mut tasks = vec![];
23+
if let Ok(pyproject) = PyProjectToml::get_default_project() {
24+
if pyproject.poe_available() {
25+
if let Some(scripts) = pyproject.get_poe_tasks() {
26+
scripts.iter().for_each(|(name, description)| {
27+
tasks.push(task!(name, "poe", description));
28+
});
29+
}
30+
}
31+
}
32+
Ok(tasks)
33+
}
34+
35+
pub fn run_task(
36+
task: &str,
37+
task_args: &[&str],
38+
global_args: &[&str],
39+
verbose: bool,
40+
) -> Result<Output, KeeperError> {
41+
let mut args = vec![];
42+
args.extend(global_args);
43+
args.push(task);
44+
args.extend(task_args);
45+
run_command("poe", &args, verbose)
46+
}
47+
48+
#[cfg(test)]
49+
mod tests {
50+
use super::*;
51+
52+
#[test]
53+
fn test_list_tasks() {
54+
let tasks = list_tasks().unwrap();
55+
for task in &tasks {
56+
println!("Task: {:?}", task);
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)