use std::io;
use std::path::Path;
use super::run_logged;
use crate::actions::verbs::Outcome;
use crate::cli_outbound::Cli;
use crate::opslog::Origin;
pub mod edit;
pub mod verb;
pub use verb::Verb;
const CLOSE: &str = "close";
const CLAIM: &str = "claim";
const UNCLAIM: &str = "unclaim";
const CREATE: &str = "create";
const UPDATE: &str = "update";
const AS: &str = "--as";
const TITLE: &str = "--title";
const BODY: &str = "--body";
const NOTE: &str = "-m";
pub fn close(
bl: &Cli,
state_root: &Path,
ts: &str,
project: &Path,
id: &str,
name: &str,
) -> io::Result<Outcome> {
run_logged(
bl,
state_root,
ts,
project,
&[CLOSE, id, AS, name],
Origin::Balls,
)
}
pub fn assign(
bl: &Cli,
state_root: &Path,
ts: &str,
project: &Path,
id: &str,
name: &str,
) -> io::Result<Outcome> {
run_logged(
bl,
state_root,
ts,
project,
&[CLAIM, id, AS, name],
Origin::Balls,
)
}
pub fn unclaim(
bl: &Cli,
state_root: &Path,
ts: &str,
project: &Path,
id: &str,
name: &str,
) -> io::Result<Outcome> {
run_logged(
bl,
state_root,
ts,
project,
&[UNCLAIM, id, AS, name],
Origin::Balls,
)
}
pub fn create(
bl: &Cli,
state_root: &Path,
ts: &str,
project: &Path,
name: &str,
fields: &edit::Create,
) -> io::Result<Outcome> {
spend(bl, state_root, ts, project, CREATE, fields.argv(name))
}
pub fn update(
bl: &Cli,
state_root: &Path,
ts: &str,
project: &Path,
id: &str,
name: &str,
fields: &edit::Update,
) -> io::Result<Outcome> {
let mut argv = vec![id.to_owned()];
argv.extend(fields.argv(name));
spend(bl, state_root, ts, project, UPDATE, argv)
}
fn spend(
bl: &Cli,
state_root: &Path,
ts: &str,
project: &Path,
verb: &str,
argv: Vec<String>,
) -> io::Result<Outcome> {
let mut args = vec![verb];
args.extend(argv.iter().map(String::as_str));
run_logged(bl, state_root, ts, project, &args, Origin::Balls)
}