Skip to content

Commit

Permalink
rustfmt fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
busticated committed Oct 15, 2023
1 parent fa508af commit 4fbbe98
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
36 changes: 24 additions & 12 deletions xtask/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl<'a> Git<'a> {
pub fn cmd(&self, args: Vec<OsString>) -> 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
Expand All @@ -33,8 +33,18 @@ impl<'a> Git<'a> {
UU: IntoIterator,
UU::Item: Into<OsString>,
{
let mut args = args1.into_iter().map(Into::<OsString>::into).collect::<Vec<_>>();
args.extend(args2.into_iter().map(Into::<OsString>::into).collect::<Vec<_>>());
let mut args = args1
.into_iter()
.map(Into::<OsString>::into)
.collect::<Vec<_>>();

args.extend(
args2
.into_iter()
.map(Into::<OsString>::into)
.collect::<Vec<_>>(),
);

args.retain(|a| !a.is_empty());
args
}
Expand All @@ -57,7 +67,7 @@ impl<'a> Git<'a> {
{
self.build_args(
vec![OsString::from("add"), path.as_ref().to_owned().into()],
arguments
arguments,
)
}

Expand All @@ -77,10 +87,7 @@ impl<'a> Git<'a> {
U: IntoIterator,
U::Item: Into<OsString>,
{
self.build_args(
vec!["commit", "--message", message.as_ref()],
arguments
)
self.build_args(vec!["commit", "--message", message.as_ref()], arguments)
}

pub fn tag<T, U>(&self, tag: T, arguments: U) -> Expression
Expand All @@ -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::*;
Expand Down Expand Up @@ -140,14 +146,20 @@ 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]
fn it_builds_args_for_the_tag_subcommand() {
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"]
);
}
}
10 changes: 6 additions & 4 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = env::args().collect();

args.remove(0); // drop executable path
Expand All @@ -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)
}
}
}

Expand Down
1 change: 0 additions & 1 deletion xtask/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub struct Options {
pub flags: TaskFlags,
}

#[allow(dead_code)]
impl Options {
pub fn new(args: Vec<String>, flags: TaskFlags) -> Result<Self, DynError> {
let re = Regex::new(r"^-*")?;
Expand Down
5 changes: 4 additions & 1 deletion xtask/src/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}
}

0 comments on commit 4fbbe98

Please sign in to comment.