Skip to content

Commit

Permalink
Fix: cargo-watch option 'why' should remove '--q' #849
Browse files Browse the repository at this point in the history
  • Loading branch information
sagiegurari committed Jun 5, 2023
1 parent 8e32702 commit d4f89d7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### v0.36.9

* Fix: '--hide-uninteresting' cli flag #859 (thanks @xxchan)
* Fix: cargo-watch option 'why' should remove '--q' #849

### v0.36.8 (2023-05-27)

Expand Down
23 changes: 14 additions & 9 deletions src/lib/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ fn create_watch_task(task: &str, options: Option<TaskWatchOptions>, flow_info: &
}
make_command = make_command.trim().to_string();

let mut watch_args = vec!["watch".to_string(), "-q".to_string()];
let mut watch_args = vec!["watch".to_string()];

match options {
Some(task_watch_options) => match task_watch_options {
Expand All @@ -501,6 +501,17 @@ fn create_watch_task(task: &str, options: Option<TaskWatchOptions>, flow_info: &
};
task_config.install_crate_args = Some(vec!["--version".to_string(), watch_version]);

match watch_options.why {
Some(option_value) => {
if option_value {
watch_args.push("--why".to_string());
} else {
watch_args.push("-q".to_string());
}
}
None => watch_args.push("-q".to_string()),
}

if let Some(option_value) = watch_options.postpone {
if option_value {
watch_args.push("--postpone".to_string());
Expand All @@ -518,12 +529,6 @@ fn create_watch_task(task: &str, options: Option<TaskWatchOptions>, flow_info: &
}
}

if let Some(option_value) = watch_options.why {
if option_value {
watch_args.push("--why".to_string());
}
}

match watch_options.watch {
Some(paths) => {
for watch_path in paths {
Expand All @@ -533,9 +538,9 @@ fn create_watch_task(task: &str, options: Option<TaskWatchOptions>, flow_info: &
_ => (),
};
}
_ => (),
_ => watch_args.push("-q".to_string()),
},
_ => (),
None => watch_args.push("-q".to_string()),
}

watch_args.extend_from_slice(&["-x".to_string(), make_command.to_string()]);
Expand Down
34 changes: 16 additions & 18 deletions src/lib/runner_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1148,20 +1148,19 @@ fn create_watch_task_with_makefile_and_all_object_options_and_cli_args() {
make_command_line.push_str(" some_task 1 2 \"3 4\"");

let args = task.args.unwrap();
assert_eq!(args.len(), 13);
assert_eq!(args.len(), 12);
assert_eq!(args[0], "watch".to_string());
assert_eq!(args[1], "-q".to_string());
assert_eq!(args[1], "--why".to_string());
assert_eq!(args[2], "--postpone".to_string());
assert_eq!(args[3], "-i".to_string());
assert_eq!(args[4], "tools/*".to_string());
assert_eq!(args[5], "--no-gitignore".to_string());
assert_eq!(args[6], "--why".to_string());
assert_eq!(args[7], "-w".to_string());
assert_eq!(args[8], "dir1".to_string());
assert_eq!(args[9], "-w".to_string());
assert_eq!(args[10], "dir2".to_string());
assert_eq!(args[11], "-x".to_string());
assert_eq!(args[12], make_command_line.to_string());
assert_eq!(args[6], "-w".to_string());
assert_eq!(args[7], "dir1".to_string());
assert_eq!(args[8], "-w".to_string());
assert_eq!(args[9], "dir2".to_string());
assert_eq!(args[10], "-x".to_string());
assert_eq!(args[11], make_command_line.to_string());
}

#[test]
Expand Down Expand Up @@ -1211,20 +1210,19 @@ fn create_watch_task_with_makefile_and_all_object_options() {
make_command_line.push_str(" some_task");

let args = task.args.unwrap();
assert_eq!(args.len(), 13);
assert_eq!(args.len(), 12);
assert_eq!(args[0], "watch".to_string());
assert_eq!(args[1], "-q".to_string());
assert_eq!(args[1], "--why".to_string());
assert_eq!(args[2], "--postpone".to_string());
assert_eq!(args[3], "-i".to_string());
assert_eq!(args[4], "tools/*".to_string());
assert_eq!(args[5], "--no-gitignore".to_string());
assert_eq!(args[6], "--why".to_string());
assert_eq!(args[7], "-w".to_string());
assert_eq!(args[8], "dir1".to_string());
assert_eq!(args[9], "-w".to_string());
assert_eq!(args[10], "dir2".to_string());
assert_eq!(args[11], "-x".to_string());
assert_eq!(args[12], make_command_line.to_string());
assert_eq!(args[6], "-w".to_string());
assert_eq!(args[7], "dir1".to_string());
assert_eq!(args[8], "-w".to_string());
assert_eq!(args[9], "dir2".to_string());
assert_eq!(args[10], "-x".to_string());
assert_eq!(args[11], make_command_line.to_string());
}

#[test]
Expand Down

0 comments on commit d4f89d7

Please sign in to comment.