use getset::{CopyGetters, WithSetters};
use tap::Pipe;
use crate::os_cmd::{CommandRepr, RunnableCommand, presets::StrVec};
impl RunnableCommand<'_> for CargoFmt {}
#[derive(Debug, Clone, WithSetters, CopyGetters)]
#[getset(set_with = "pub", get_copy = "pub with_prefix")]
pub struct CargoFmt {
nightly: bool,
}
impl Default for CargoFmt {
fn default() -> Self {
Self { nightly: true }
}
}
impl From<CargoFmt> for CommandRepr<'_> {
#[allow(clippy::unnecessary_lazy_evaluations)]
fn from(value: CargoFmt) -> Self {
"cargo"
.pipe(core::iter::once)
.chain(
value
.get_nightly()
.then(|| "+nightly"),
)
.chain(["fmt"])
.collect::<StrVec<3>>()
.into_boxed_slice()
.pipe(CommandRepr::Slice)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[ignore]
#[test]
fn test_cargo_fmt_cmd() {
let cmd: CommandRepr = CargoFmt::default()
.with_nightly(true)
.into();
dbg!(&cmd);
}
}