Skip to content

Commit

Permalink
Use more flexible slices instead of &Vec<&str>
Browse files Browse the repository at this point in the history
  • Loading branch information
syl20bnr committed Sep 27, 2024
1 parent fb21914 commit 57f41e1
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 38 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/tracel-xtask/src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub(crate) fn run_build(
group!("Build Workspace");
run_process_for_workspace(
"cargo",
vec!["build", "--workspace", "--color", "always"],
&["build", "--workspace", "--color", "always"],
excluded,
None,
None,
Expand All @@ -54,7 +54,7 @@ pub(crate) fn run_build(
run_process_for_package(
"cargo",
&member.name,
&vec!["build", "-p", &member.name, "--color", "always"],
&["build", "-p", &member.name, "--color", "always"],
excluded,
only,
&format!("Build command failed for {}", &member.name),
Expand Down
2 changes: 1 addition & 1 deletion crates/tracel-xtask/src/commands/bump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn bump(command: &BumpSubCommand) -> anyhow::Result<()> {
ensure_cargo_crate_is_installed("cargo-edit", None, None, false)?;
run_process(
"cargo",
&vec!["set-version", "--bump", &command.to_string()],
&["set-version", "--bump", &command.to_string()],
None,
None,
&format!("Error trying to bump {command} version"),
Expand Down
12 changes: 6 additions & 6 deletions crates/tracel-xtask/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn run_audit() -> anyhow::Result<()> {
ensure_cargo_crate_is_installed("cargo-audit", Some("fix"), None, false)?;
run_process(
"cargo",
&vec!["audit", "-q", "--color", "always"],
&["audit", "-q", "--color", "always"],
None,
None,
"Audit check execution failed",
Expand All @@ -67,7 +67,7 @@ fn run_format(target: &Target, excluded: &[String], only: &[String]) -> anyhow::
group!("Format Workspace");
run_process_for_workspace(
"cargo",
vec!["fmt", "--check"],
&["fmt", "--check"],
&[],
None,
None,
Expand All @@ -89,7 +89,7 @@ fn run_format(target: &Target, excluded: &[String], only: &[String]) -> anyhow::
run_process_for_package(
"cargo",
&member.name,
&vec!["fmt", "--check", "-p", &member.name],
&["fmt", "--check", "-p", &member.name],
excluded,
only,
&format!("Format check execution failed for {}", &member.name),
Expand All @@ -114,7 +114,7 @@ fn run_lint(target: &Target, excluded: &[String], only: &[String]) -> anyhow::Re
group!("Lint Workspace");
run_process_for_workspace(
"cargo",
vec![
&[
"clippy",
"--no-deps",
"--color=always",
Expand Down Expand Up @@ -143,7 +143,7 @@ fn run_lint(target: &Target, excluded: &[String], only: &[String]) -> anyhow::Re
run_process_for_package(
"cargo",
&member.name,
&vec![
&[
"clippy",
"--no-deps",
"--color=always",
Expand Down Expand Up @@ -178,7 +178,7 @@ fn run_typos() -> anyhow::Result<()> {
group!("Typos");
run_process(
"typos",
&vec!["--diff", "--color", "always"],
&["--diff", "--color", "always"],
None,
None,
"Typos check execution failed",
Expand Down
4 changes: 2 additions & 2 deletions crates/tracel-xtask/src/commands/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub(crate) fn run_compile(
group!("Compile Workspace");
run_process_for_workspace(
"cargo",
vec!["check", "--workspace"],
&["check", "--workspace"],
excluded,
None,
None,
Expand All @@ -54,7 +54,7 @@ pub(crate) fn run_compile(
run_process_for_package(
"cargo",
&member.name,
&vec!["check", "-p", &member.name],
&["check", "-p", &member.name],
excluded,
only,
&format!("Compilation failed for {}", &member.name),
Expand Down
4 changes: 2 additions & 2 deletions crates/tracel-xtask/src/commands/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn run_cargo_deny() -> anyhow::Result<()> {
group!("Cargo: run deny checks");
run_process(
"cargo",
&vec!["deny", "check"],
&["deny", "check"],
None,
None,
"Some dependencies don't meet the requirements!",
Expand All @@ -42,7 +42,7 @@ fn run_cargo_machete() -> anyhow::Result<()> {
group!("Cargo: run unused dependencies checks");
run_process(
"cargo",
&vec!["machete"],
&["machete"],
None,
None,
"Unused dependencies found!",
Expand Down
8 changes: 4 additions & 4 deletions crates/tracel-xtask/src/commands/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn run_documentation_build(
group!("Build Workspace documentation");
run_process_for_workspace(
"cargo",
vec!["doc", "--workspace", "--no-deps", "--color=always"],
&["doc", "--workspace", "--no-deps", "--color=always"],
excluded,
None,
None,
Expand All @@ -57,7 +57,7 @@ fn run_documentation_build(
run_process_for_package(
"cargo",
&member.name,
&vec!["doc", "-p", &member.name, "--no-deps", "--color=always"],
&["doc", "-p", &member.name, "--no-deps", "--color=always"],
excluded,
only,
&format!("Format check execution failed for {}", &member.name),
Expand Down Expand Up @@ -86,7 +86,7 @@ pub(crate) fn run_documentation(
group!("Workspace Documentation Tests");
run_process_for_workspace(
"cargo",
vec!["test", "--workspace", "--doc", "--color", "always"],
&["test", "--workspace", "--doc", "--color", "always"],
excluded,
Some(r"Doc-tests (\w+)"),
Some("Doc Tests"),
Expand Down Expand Up @@ -125,7 +125,7 @@ fn run_doc_test(
run_process_for_package(
"cargo",
&member.name,
&vec!["test", "--doc", "-p", &member.name],
&["test", "--doc", "-p", &member.name],
excluded,
only,
&format!(
Expand Down
12 changes: 6 additions & 6 deletions crates/tracel-xtask/src/commands/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub(crate) fn run_audit() -> anyhow::Result<()> {
group!("Audit Rust Dependencies");
run_process(
"cargo",
&vec!["audit", "-q", "--color", "always", "fix"],
&["audit", "-q", "--color", "always", "fix"],
None,
None,
"Audit check execution failed",
Expand All @@ -72,7 +72,7 @@ fn run_format(target: &Target, excluded: &Vec<String>, only: &Vec<String>) -> Re
group!("Format Workspace");
run_process_for_workspace(
"cargo",
vec!["fmt"],
&["fmt"],
&[],
None,
None,
Expand All @@ -93,7 +93,7 @@ fn run_format(target: &Target, excluded: &Vec<String>, only: &Vec<String>) -> Re
run_process_for_package(
"cargo",
&member.name,
&vec!["fmt", "-p", &member.name],
&["fmt", "-p", &member.name],
excluded,
only,
&format!("Format check execution failed for {}", &member.name),
Expand All @@ -118,7 +118,7 @@ fn run_lint(target: &Target, excluded: &Vec<String>, only: &Vec<String>) -> anyh
group!("Lint Workspace");
run_process_for_workspace(
"cargo",
vec![
&[
"clippy",
"--no-deps",
"--fix",
Expand Down Expand Up @@ -149,7 +149,7 @@ fn run_lint(target: &Target, excluded: &Vec<String>, only: &Vec<String>) -> anyh
run_process_for_package(
"cargo",
&member.name,
&vec![
&[
"clippy",
"--no-deps",
"--fix",
Expand Down Expand Up @@ -185,7 +185,7 @@ pub(crate) fn run_typos() -> anyhow::Result<()> {
group!("Typos");
run_process(
"typos",
&vec!["--write-changes", "--color", "always"],
&["--write-changes", "--color", "always"],
None,
None,
"Some typos have been found and cannot be fixed.",
Expand Down
2 changes: 1 addition & 1 deletion crates/tracel-xtask/src/commands/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn publish(crate_name: String) -> anyhow::Result<()> {
// Perform dry-run to ensure everything is good for publishing
run_process(
"cargo",
&vec!["publish", "-p", &crate_name, "--dry-run"],
&["publish", "-p", &crate_name, "--dry-run"],
None,
None,
&format!("Publish dry run failed for crate '{}'.", &crate_name),
Expand Down
9 changes: 5 additions & 4 deletions crates/tracel-xtask/src/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ pub fn run_unit(target: &Target, args: &TestCmdArgs) -> Result<()> {
.map(|s| s.to_string())
.collect::<Vec<String>>();
push_optional_args(&mut cmd_args, args);
// let cmd_args: Vec<&str> = cmd_args.iter().map(String::as_str).collect();
run_process_for_workspace(
"cargo",
cmd_args.iter().map(String::as_str).collect(),
&cmd_args.iter().map(String::as_str).collect::<Vec<&str>>(),
&args.exclude,
Some(r".*target/[^/]+/deps/([^-\s]+)"),
Some("Unit Tests"),
Expand Down Expand Up @@ -115,7 +116,7 @@ fn run_unit_test(member: &WorkspaceMember, args: &TestCmdArgs) -> Result<(), any
run_process_for_package(
"cargo",
&member.name,
&cmd_args.iter().map(String::as_str).collect(),
&cmd_args.iter().map(String::as_str).collect::<Vec<&str>>(),
&args.exclude,
&args.only,
&format!("Failed to execute unit test for '{}'", &member.name),
Expand All @@ -140,7 +141,7 @@ pub fn run_integration(target: &Target, args: &TestCmdArgs) -> anyhow::Result<()
push_optional_args(&mut cmd_args, args);
run_process_for_workspace(
"cargo",
cmd_args.iter().map(String::as_str).collect(),
&cmd_args.iter().map(String::as_str).collect::<Vec<&str>>(),
&args.exclude,
Some(r".*target/[^/]+/deps/([^-\s]+)"),
Some("Integration Tests"),
Expand Down Expand Up @@ -187,7 +188,7 @@ fn run_integration_test(member: &WorkspaceMember, args: &TestCmdArgs) -> Result<
run_process_for_package(
"cargo",
&member.name,
&cmd_args.iter().map(String::as_str).collect(),
&cmd_args.iter().map(String::as_str).collect::<Vec<&str>>(),
&args.exclude,
&args.only,
&format!("Failed to execute integration test for '{}'", &member.name),
Expand Down
4 changes: 2 additions & 2 deletions crates/tracel-xtask/src/commands/vulnerabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn run_cargo_careful() -> anyhow::Result<()> {
group!("Cargo: careful setup");
run_process(
"cargo",
&vec!["careful", "setup"],
&["careful", "setup"],
None,
None,
"Error preparing cargo sysroot.",
Expand All @@ -67,7 +67,7 @@ fn run_cargo_careful() -> anyhow::Result<()> {
group!("Cargo: run careful checks");
run_process(
"cargo",
&vec!["careful", "test"],
&["careful", "test"],
None,
None,
"Cargo careful test has errors.",
Expand Down
8 changes: 4 additions & 4 deletions crates/tracel-xtask/src/utils/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{endgroup, group};
/// Run a process
pub fn run_process(
name: &str,
args: &Vec<&str>,
args: &[&str],
envs: Option<HashMap<&str, &str>>,
path: Option<&Path>,
error_msg: &str,
Expand Down Expand Up @@ -50,7 +50,7 @@ pub fn run_process(
#[allow(clippy::too_many_arguments)]
pub fn run_process_for_workspace<'a>(
name: &str,
args: Vec<&'a str>,
args: &[&'a str],
excluded: &'a [String],
group_regexp: Option<&str>,
group_name: Option<&str>,
Expand All @@ -61,7 +61,7 @@ pub fn run_process_for_workspace<'a>(
let group_rx: Option<Regex> = group_regexp.map(|r| Regex::new(r).unwrap());
// split the args between cargo args and binary args so that we can extend the cargo args
// and then append the binary args back.
let (cargo_args, binary_args) = split_vector(&args, "--");
let (cargo_args, binary_args) = split_vector(args, "--");
let mut cmd_args = cargo_args.to_owned();
excluded
.iter()
Expand Down Expand Up @@ -160,7 +160,7 @@ pub fn run_process_for_workspace<'a>(
pub fn run_process_for_package(
name: &str,
package: &String,
args: &Vec<&str>,
args: &[&str],
excluded: &[String],
only: &[String],
error_msg: &str,
Expand Down
4 changes: 2 additions & 2 deletions crates/tracel-xtask/src/utils/rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub fn rustup_add_target(target: &str) -> anyhow::Result<()> {
group!("Rustup: add target {}", target);
run_process(
"rustup",
&vec!["target", "add", target],
&["target", "add", target],
None,
None,
&format!("Failed to add target {target}"),
Expand All @@ -21,7 +21,7 @@ pub fn rustup_add_component(component: &str) -> anyhow::Result<()> {
group!("Rustup: add component {}", component);
run_process(
"rustup",
&vec!["component", "add", component],
&["component", "add", component],
None,
None,
&format!("Failed to add component {component}"),
Expand Down

0 comments on commit 57f41e1

Please sign in to comment.