Make Command::run() accept a single string for convenience
We can fall back on the standard constructor when we have dynamic input
This commit is contained in:
parent
a96d5a920b
commit
5023356dd2
@ -34,12 +34,10 @@ pub struct Utf8Output {
|
||||
}
|
||||
|
||||
pub trait CommandExt {
|
||||
fn run<I, S>(cmd_and_args: I) -> Result<()>
|
||||
where
|
||||
I: IntoIterator<Item = S>,
|
||||
S: AsRef<OsStr>,
|
||||
{
|
||||
let mut all_args = cmd_and_args.into_iter();
|
||||
/// A shortcut for when the command and its args are known up-front and have
|
||||
/// no spaces in them.
|
||||
fn run(cmd_and_args: impl AsRef<str>) -> Result<()> {
|
||||
let mut all_args = cmd_and_args.as_ref().split(' ');
|
||||
Command::new(all_args.next().unwrap())
|
||||
.args(all_args)
|
||||
.ensure_success()?;
|
||||
@ -111,9 +109,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_run() {
|
||||
assert_eq!(
|
||||
Command::run(["fakefake", "1", "2"])
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
Command::run("fakefake 1 2").unwrap_err().to_string(),
|
||||
"Failed to execute: fakefake 1 2"
|
||||
);
|
||||
#[cfg(not(windows))]
|
||||
|
@ -198,14 +198,14 @@ impl LintContext {
|
||||
}
|
||||
|
||||
fn check_cargo_deny() -> Result<()> {
|
||||
Command::run(["cargo", "install", "cargo-deny@0.13.5"])?;
|
||||
Command::run(["cargo", "deny", "check", "-A", "duplicate"])?;
|
||||
Command::run("cargo install cargo-deny@0.13.5")?;
|
||||
Command::run("cargo deny check -A duplicate")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update_hakari() -> Result<()> {
|
||||
Command::run(["cargo", "install", "cargo-hakari@0.9.23"])?;
|
||||
Command::run(["cargo", "hakari", "generate"])?;
|
||||
Command::run("cargo install cargo-hakari@0.9.23")?;
|
||||
Command::run("cargo hakari generate")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -258,7 +258,7 @@ fn check_for_unstaged_changes() {
|
||||
|
||||
fn generate_licences() -> Result<String> {
|
||||
if which::which("cargo-license").is_err() {
|
||||
Command::run(["cargo", "install", "cargo-license@0.5.1"])?;
|
||||
Command::run("cargo install cargo-license@0.5.1")?;
|
||||
}
|
||||
let output = Command::run_with_output([
|
||||
"cargo-license",
|
||||
|
Loading…
Reference in New Issue
Block a user