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;
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 reassign(
bl: &Cli,
state_root: &Path,
ts: &str,
project: &Path,
id: &str,
from: &str,
to: &str,
) -> io::Result<Outcome> {
unclaim(bl, state_root, ts, project, id, from)?;
assign(bl, state_root, ts, project, id, to)
}
pub fn create(
bl: &Cli,
state_root: &Path,
ts: &str,
project: &Path,
title: &str,
name: &str,
body: Option<&str>,
) -> io::Result<Outcome> {
let mut args = vec![CREATE, title, AS, name];
if let Some(b) = body {
args.push(BODY);
args.push(b);
}
run_logged(bl, state_root, ts, project, &args, Origin::Balls)
}
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct Update {
pub title: Option<String>,
pub body: Option<String>,
pub note: Option<String>,
}
impl Update {
pub fn of(title: &Option<String>, body: &Option<String>, note: &Option<String>) -> Self {
Self {
title: title.clone(),
body: body.clone(),
note: note.clone(),
}
}
}
pub fn update(
bl: &Cli,
state_root: &Path,
ts: &str,
project: &Path,
id: &str,
name: &str,
fields: &Update,
) -> io::Result<Outcome> {
let mut args = vec![UPDATE, id, AS, name];
if let Some(t) = &fields.title {
args.push(TITLE);
args.push(t);
}
if let Some(b) = &fields.body {
args.push(BODY);
args.push(b);
}
if let Some(n) = &fields.note {
args.push(NOTE);
args.push(n);
}
run_logged(bl, state_root, ts, project, &args, Origin::Balls)
}