diff --git a/xtask/src/git.rs b/xtask/src/git.rs index 384a51b..0854c3d 100644 --- a/xtask/src/git.rs +++ b/xtask/src/git.rs @@ -16,7 +16,7 @@ impl<'a> Git<'a> { pub fn cmd(&self, args: Vec) -> Expression { let mut args = args.clone(); - if self.opts.has("dry-run"){ + if self.opts.has("dry-run") { args.insert(0, "skipping:".into()); args.insert(1, "git".into()); // TODO (mirande): windows? see: https://stackoverflow.com/a/61857874/579167 @@ -33,8 +33,18 @@ impl<'a> Git<'a> { UU: IntoIterator, UU::Item: Into, { - let mut args = args1.into_iter().map(Into::::into).collect::>(); - args.extend(args2.into_iter().map(Into::::into).collect::>()); + let mut args = args1 + .into_iter() + .map(Into::::into) + .collect::>(); + + args.extend( + args2 + .into_iter() + .map(Into::::into) + .collect::>(), + ); + args.retain(|a| !a.is_empty()); args } @@ -57,7 +67,7 @@ impl<'a> Git<'a> { { self.build_args( vec![OsString::from("add"), path.as_ref().to_owned().into()], - arguments + arguments, ) } @@ -77,10 +87,7 @@ impl<'a> Git<'a> { U: IntoIterator, U::Item: Into, { - self.build_args( - vec!["commit", "--message", message.as_ref()], - arguments - ) + self.build_args(vec!["commit", "--message", message.as_ref()], arguments) } pub fn tag(&self, tag: T, arguments: U) -> Expression @@ -101,12 +108,11 @@ impl<'a> Git<'a> { { self.build_args( vec!["tag", tag.as_ref(), "--message", tag.as_ref()], - arguments + arguments, ) } } - #[cfg(test)] mod tests { use super::*; @@ -140,7 +146,10 @@ mod tests { let opts = Options::new(vec![], task_flags! {}).unwrap(); let git = Git::new(&opts); let args = git.commit_raw("my message", ["--one", "--two"]); - assert_eq!(args, ["commit", "--message", "my message", "--one", "--two"]); + assert_eq!( + args, + ["commit", "--message", "my message", "--one", "--two"] + ); } #[test] @@ -148,6 +157,9 @@ mod tests { let opts = Options::new(vec![], task_flags! {}).unwrap(); let git = Git::new(&opts); let args = git.tag_raw("my tag", ["--one", "--two"]); - assert_eq!(args, ["tag", "my tag", "--message", "my tag", "--one", "--two"]); + assert_eq!( + args, + ["tag", "my tag", "--message", "my tag", "--one", "--two"] + ); } } diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 7398238..41df5c5 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -32,9 +32,6 @@ fn main() { } fn try_main() -> Result<(), DynError> { - let cargo_cmd = get_cargo_cmd(); - let root_path = get_root_path(&cargo_cmd)?; - let mut workspace = Workspace::from_path(cargo_cmd, root_path)?; let mut args: Vec = env::args().collect(); args.remove(0); // drop executable path @@ -57,8 +54,13 @@ fn try_main() -> Result<(), DynError> { let tasks = init_tasks(); match tasks.get(cmd.clone()) { - Some(task) => task.exec(args, &mut workspace, &tasks), None => print_help(cmd, args, tasks), + Some(task) => { + let cargo_cmd = get_cargo_cmd(); + let root_path = get_root_path(&cargo_cmd)?; + let mut workspace = Workspace::from_path(cargo_cmd, root_path)?; + task.exec(args, &mut workspace, &tasks) + } } } diff --git a/xtask/src/options.rs b/xtask/src/options.rs index 5aba52a..231c951 100644 --- a/xtask/src/options.rs +++ b/xtask/src/options.rs @@ -11,7 +11,6 @@ pub struct Options { pub flags: TaskFlags, } -#[allow(dead_code)] impl Options { pub fn new(args: Vec, flags: TaskFlags) -> Result { let re = Regex::new(r"^-*")?; diff --git a/xtask/src/toml.rs b/xtask/src/toml.rs index b8a7453..1f1dede 100644 --- a/xtask/src/toml.rs +++ b/xtask/src/toml.rs @@ -194,6 +194,9 @@ mod tests { fn it_gets_description_field() { let fake_crate_root = PathBuf::from(""); let toml = Toml::new(fake_crate_root).load().unwrap(); - assert_eq!(toml.get_description().unwrap(), "internal-only crate used to orchestrate repo tasks"); + assert_eq!( + toml.get_description().unwrap(), + "internal-only crate used to orchestrate repo tasks" + ); } }