Skip to content

Commit

Permalink
fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Emilgardis committed Sep 8, 2022
1 parent 174bf23 commit c1a9ee8
Show file tree
Hide file tree
Showing 16 changed files with 91 additions and 93 deletions.
18 changes: 9 additions & 9 deletions src/bin/commands/containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,9 @@ fn get_cross_volumes(
use cross::docker::remote::VOLUME_PREFIX;
let stdout = docker::subcommand(engine, "volume")
.arg("list")
.args(&["--format", "{{.Name}}"])
.args(["--format", "{{.Name}}"])
// handles simple regex: ^ for start of line.
.args(&["--filter", &format!("name=^{VOLUME_PREFIX}")])
.args(["--filter", &format!("name=^{VOLUME_PREFIX}")])
.run_and_get_stdout(msg_info)?;

let mut volumes: Vec<String> = stdout.lines().map(|s| s.to_string()).collect();
Expand Down Expand Up @@ -371,7 +371,7 @@ pub fn prune_volumes(
msg_info: &mut MessageInfo,
) -> cross::Result<()> {
let mut command = docker::subcommand(engine, "volume");
command.args(&["prune", "--force"]);
command.args(["prune", "--force"]);
if execute {
command.run(msg_info, false).map_err(Into::into)
} else {
Expand Down Expand Up @@ -405,7 +405,7 @@ pub fn create_persistent_volume(
}

docker::subcommand(engine, "volume")
.args(&["create", &volume])
.args(["create", &volume])
.run_and_get_status(msg_info, false)?;

// stop the container if it's already running
Expand All @@ -422,9 +422,9 @@ pub fn create_persistent_volume(
// create a dummy running container to copy data over
let mount_prefix = docker::remote::MOUNT_PREFIX;
let mut docker = docker::subcommand(engine, "run");
docker.args(&["--name", &container]);
docker.args(["--name", &container]);
docker.arg("--rm");
docker.args(&["-v", &format!("{}:{}", volume, mount_prefix)]);
docker.args(["-v", &format!("{}:{}", volume, mount_prefix)]);
docker.arg("-d");
let is_tty = io::Stdin::is_atty() && io::Stdout::is_atty() && io::Stderr::is_atty();
if is_tty {
Expand All @@ -437,7 +437,7 @@ pub fn create_persistent_volume(
// a TTY. this has a few issues though: now, the
// container no longer responds to signals, so the
// container will need to be sig-killed.
docker.args(&["sh", "-c", "sleep infinity"]);
docker.args(["sh", "-c", "sleep infinity"]);
}
// store first, since failing to non-existing container is fine
docker::remote::create_container_deleter(engine.clone(), container.clone());
Expand Down Expand Up @@ -501,9 +501,9 @@ fn get_cross_containers(
use cross::docker::remote::VOLUME_PREFIX;
let stdout = docker::subcommand(engine, "ps")
.arg("-a")
.args(&["--format", "{{.Names}}: {{.State}}"])
.args(["--format", "{{.Names}}: {{.State}}"])
// handles simple regex: ^ for start of line.
.args(&["--filter", &format!("name=^{VOLUME_PREFIX}")])
.args(["--filter", &format!("name=^{VOLUME_PREFIX}")])
.run_and_get_stdout(msg_info)?;

let mut containers: Vec<String> = stdout.lines().map(|s| s.to_string()).collect();
Expand Down
8 changes: 4 additions & 4 deletions src/bin/commands/images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ fn get_cross_images(
local: bool,
) -> cross::Result<Vec<Image>> {
let mut images: BTreeSet<_> = cross::docker::subcommand(engine, "images")
.args(&["--format", "{{.Repository}}:{{.Tag}} {{.ID}}"])
.args(&[
.args(["--format", "{{.Repository}}:{{.Tag}} {{.ID}}"])
.args([
"--filter",
&format!("label={}.for-cross-target", cross::CROSS_LABEL_DOMAIN),
])
Expand All @@ -178,7 +178,7 @@ fn get_cross_images(
.collect();

let stdout = cross::docker::subcommand(engine, "images")
.args(&["--format", "{{.Repository}}:{{.Tag}} {{.ID}}"])
.args(["--format", "{{.Repository}}:{{.Tag}} {{.ID}}"])
.run_and_get_stdout(msg_info)?;
let ids: Vec<_> = images.iter().map(|i| i.id.to_string()).collect();
images.extend(
Expand Down Expand Up @@ -239,7 +239,7 @@ fn get_image_target(
}
}
let mut command = cross::docker::subcommand(engine, "inspect");
command.args(&[
command.args([
"--format",
&format!(
r#"{{{{index .Config.Labels "{}.for-cross-target"}}}}"#,
Expand Down
4 changes: 2 additions & 2 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn commit_info() -> String {

fn commit_hash() -> Result<String, Some> {
let output = Command::new("git")
.args(&["rev-parse", "--short", "HEAD"])
.args(["rev-parse", "--short", "HEAD"])
.output()?;

if output.status.success() {
Expand All @@ -51,7 +51,7 @@ fn commit_hash() -> Result<String, Some> {

fn commit_date() -> Result<String, Some> {
let output = Command::new("git")
.args(&["log", "-1", "--date=short", "--pretty=format:%cd"])
.args(["log", "-1", "--date=short", "--pretty=format:%cd"])
.output()?;

if output.status.success() {
Expand Down
2 changes: 1 addition & 1 deletion src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub fn cargo_metadata_with_args(
if let Some(channel) = args.and_then(|x| x.channel.as_deref()) {
command.arg(format!("+{channel}"));
}
command.arg("metadata").args(&["--format-version", "1"]);
command.arg("metadata").args(["--format-version", "1"]);
if let Some(cd) = cd {
command.current_dir(cd);
}
Expand Down
4 changes: 2 additions & 2 deletions src/docker/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ impl<'a> Dockerfile<'a> {
opts.contains("--load") || opts.contains("--output")
});
if options.engine.kind.is_docker() && !has_output {
docker_build.args(&["--output", "type=docker"]);
docker_build.args(["--output", "type=docker"]);
};

if let Some(context) = self.context() {
docker_build.arg(&context);
docker_build.arg(context);
} else {
docker_build.arg(paths.host_root());
}
Expand Down
2 changes: 1 addition & 1 deletion src/docker/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ impl ImagePlatform {
&& Some(&self.os) == engine.os.as_ref()
{
} else {
cmd.args(&["--platform", &self.docker_platform()]);
cmd.args(["--platform", &self.docker_platform()]);
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/docker/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use eyre::Context;
// NOTE: host path must be absolute
fn mount(docker: &mut Command, host_path: &Path, absolute_path: &Path, prefix: &str) -> Result<()> {
let mount_path = absolute_path.as_posix_absolute()?;
docker.args(&[
docker.args([
"-v",
&format!("{}:{prefix}{}:z", host_path.to_utf8()?, mount_path),
]);
Expand Down Expand Up @@ -62,36 +62,36 @@ pub(crate) fn run(
docker_user_id(&mut docker, engine.kind);

docker
.args(&[
.args([
"-v",
&format!("{}:{}:z", dirs.xargo.to_utf8()?, dirs.xargo_mount_path()),
])
.args(&[
.args([
"-v",
&format!("{}:{}:z", dirs.cargo.to_utf8()?, dirs.cargo_mount_path()),
])
// Prevent `bin` from being mounted inside the Docker container.
.args(&["-v", &format!("{}/bin", dirs.cargo_mount_path())]);
docker.args(&[
.args(["-v", &format!("{}/bin", dirs.cargo_mount_path())]);
docker.args([
"-v",
&format!("{}:{}:z", dirs.host_root.to_utf8()?, dirs.mount_root),
]);
docker
.args(&[
.args([
"-v",
&format!(
"{}:{}:z,ro",
dirs.get_sysroot().to_utf8()?,
dirs.sysroot_mount_path()
),
])
.args(&["-v", &format!("{}:/target:z", dirs.target.to_utf8()?)]);
.args(["-v", &format!("{}:/target:z", dirs.target.to_utf8()?)]);
docker_cwd(&mut docker, &paths)?;

// When running inside NixOS or using Nix packaging we need to add the Nix
// Store to the running container so it can load the needed binaries.
if let Some(ref nix_store) = dirs.nix_store {
docker.args(&[
docker.args([
"-v",
&format!(
"{}:{}:z",
Expand All @@ -113,7 +113,7 @@ pub(crate) fn run(

docker
.arg(&image_name)
.args(&["sh", "-c", &build_command(dirs, &cmd)])
.args(["sh", "-c", &build_command(dirs, &cmd)])
.run_and_get_status(msg_info, false)
.map_err(Into::into)
}
27 changes: 13 additions & 14 deletions src/docker/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ fn create_volume_dir(
// make our parent directory if needed
subcommand_or_exit(engine, "exec")?
.arg(container)
.args(&[
.args([
"sh",
"-c",
&format!("mkdir -p '{}'", dir.as_posix_absolute()?),
Expand Down Expand Up @@ -210,7 +210,7 @@ fn container_path_exists(
) -> Result<bool> {
Ok(subcommand_or_exit(engine, "exec")?
.arg(container)
.args(&[
.args([
"bash",
"-c",
&format!("[[ -d '{}' ]]", path.as_posix_absolute()?),
Expand Down Expand Up @@ -659,7 +659,7 @@ rm \"{PATH}\"

subcommand_or_exit(engine, "exec")?
.arg(container)
.args(&["sh", "-c", &script.join("\n")])
.args(["sh", "-c", &script.join("\n")])
.run_and_get_status(msg_info, true)
}

Expand Down Expand Up @@ -812,9 +812,9 @@ pub fn container_state(
msg_info: &mut MessageInfo,
) -> Result<ContainerState> {
let stdout = command(engine)
.args(&["ps", "-a"])
.args(&["--filter", &format!("name={container}")])
.args(&["--format", "{{.State}}"])
.args(["ps", "-a"])
.args(["--filter", &format!("name={container}")])
.args(["--format", "{{.State}}"])
.run_and_get_stdout(msg_info)?;
ContainerState::new(stdout.trim())
}
Expand Down Expand Up @@ -946,13 +946,13 @@ pub(crate) fn run(
.image
.platform
.specify_platform(&options.engine, &mut docker);
docker.args(&["--name", &container]);
docker.args(["--name", &container]);
docker.arg("--rm");
let volume_mount = match volume {
VolumeId::Keep(ref id) => format!("{id}:{mount_prefix}"),
VolumeId::Discard => mount_prefix.to_owned(),
};
docker.args(&["-v", &volume_mount]);
docker.args(["-v", &volume_mount]);

let mut volumes = vec![];
docker_mount(
Expand All @@ -968,7 +968,7 @@ pub(crate) fn run(
.wrap_err("when copying seccomp profile")?;

// Prevent `bin` from being mounted inside the Docker container.
docker.args(&["-v", &format!("{mount_prefix}/cargo/bin")]);
docker.args(["-v", &format!("{mount_prefix}/cargo/bin")]);

// When running inside NixOS or using Nix packaging we need to add the Nix
// Store to the running container so it can load the needed binaries.
Expand Down Expand Up @@ -999,7 +999,7 @@ pub(crate) fn run(
// a TTY. this has a few issues though: now, the
// container no longer responds to signals, so the
// container will need to be sig-killed.
docker.args(&["sh", "-c", "sleep infinity"]);
docker.args(["sh", "-c", "sleep infinity"]);
}

// store first, since failing to non-existing container is fine
Expand Down Expand Up @@ -1202,7 +1202,7 @@ symlink_recurse \"${{prefix}}\"
}
subcommand_or_exit(engine, "exec")?
.arg(&container)
.args(&["sh", "-c", &symlink.join("\n")])
.args(["sh", "-c", &symlink.join("\n")])
.run_and_get_status(msg_info, false)
.wrap_err("when creating symlinks to provide consistent host/mount paths")?;

Expand All @@ -1219,7 +1219,7 @@ symlink_recurse \"${{prefix}}\"
)?;
docker_cwd(&mut docker, &paths)?;
docker.arg(&container);
docker.args(&["sh", "-c", &build_command(dirs, &cmd)]);
docker.args(["sh", "-c", &build_command(dirs, &cmd)]);
bail_container_exited!();
let status = docker
.run_and_get_status(msg_info, false)
Expand All @@ -1236,8 +1236,7 @@ symlink_recurse \"${{prefix}}\"
.arg("-a")
.arg(&format!("{container}:{}", target_dir.as_posix_absolute()?))
.arg(
&dirs
.target
dirs.target
.parent()
.expect("target directory should have a parent"),
)
Expand Down
Loading

0 comments on commit c1a9ee8

Please sign in to comment.