use assert_cmd::{cargo, Command};
use std::path::Path;
pub struct TreeflowCommand {
cmd: Command,
}
#[allow(dead_code)]
impl TreeflowCommand {
pub fn new<P: AsRef<Path>>(config_dir: P) -> Self {
let mut cmd = cargo::cargo_bin_cmd!("treeflow");
cmd.env("TREEFLOW_CONFIG_DIR", config_dir.as_ref());
Self { cmd }
}
pub fn config(mut self) -> Self {
self.cmd.arg("config");
self
}
pub fn current_dir<P: AsRef<Path>>(mut self, path: P) -> Self {
self.cmd.current_dir(path);
self
}
pub fn init(mut self, shell: &str, enable_shorthands: bool) -> Self {
self.cmd.args(["init", shell]);
if enable_shorthands {
self.cmd.arg("--enable-shorthands");
}
self
}
pub fn primary(mut self) -> Self {
self.cmd.arg("primary");
self
}
pub fn worktype_add(mut self, type_name: &str, prefix: &str) -> Self {
self.cmd.args(["worktype", "add", type_name, "--prefix", prefix]);
self
}
pub fn worktype_list(mut self) -> Self {
self.cmd.args(["worktype", "list"]);
self
}
pub fn worktype_remove(mut self, type_name: &str) -> Self {
self.cmd.args(["worktype", "remove", type_name]);
self
}
pub fn project_add(mut self, repository: &Path, worktrees: Option<&Path>) -> Self {
let mut args = vec!["project", "add", repository.to_str().expect("repository path should be representable as a string")];
if let Some(wt) = worktrees {
args.extend(["--worktrees-dir", wt.to_str().expect("repository path should be representable as a string")]);
}
self.cmd.args(&args);
self
}
pub fn project_list(mut self) -> Self {
self.cmd.args(["project", "list"]);
self
}
pub fn project_remove(mut self, repository: &Path) -> Self {
self.cmd.args(["project", "remove", repository.to_str().expect("repository path should be representable as a string")]);
self
}
pub fn start(mut self, work_name: &str, work_type: &str) -> Self {
self.cmd.args([work_type, work_name]);
self
}
pub fn review(mut self, branch: &str) -> Self {
self.cmd.args(["review", branch]);
self
}
pub fn cmd(self) -> Command {
self.cmd
}
}