Skip to content

Commit

Permalink
feat: redo list command to list relevant information and look nicer
Browse files Browse the repository at this point in the history
  • Loading branch information
sandorex committed Sep 11, 2024
1 parent 7899bd3 commit ea86dff
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/commands/cmd_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,36 @@ use crate::{util::Engine, ExitResult};

pub fn print_containers(engine: Engine, dry_run: bool) -> ExitResult {
let mut cmd = Command::new(&engine.path);
cmd.args(["container", "ls", "--filter", format!("label={}", crate::BIN_NAME).as_str()]);
cmd.args([
"container", "ls",
"--filter", format!("label={}", crate::BIN_NAME).as_str(),
"--format", "{{.Names}}|{{.Image}}|{{.Labels.host_dir}}|{{.Ports}}"
]);

if dry_run {
cmd.print_escaped_cmd()
} else {
cmd.status()
.expect(crate::ENGINE_ERR_MSG)
.to_exitcode()
let output = cmd.output()
.expect(crate::ENGINE_ERR_MSG);

if output.status.success() {
println!(
"{0: <14} {1: <40} {2: <35} {3: <40}",
"NAMES", "IMAGE", "WS", "PORTS"
);
let stdout = String::from_utf8_lossy(&output.stdout);
for i in stdout.lines() {
let columns: Vec<&str> = i.trim().split("|").collect();

println!(
"{0: <14} {1: <40} {2: <40} {3: <30}",
columns[0], columns[1], columns[2], columns[3],
);
}

Ok(())
} else {
output.to_exitcode()
}
}
}

0 comments on commit ea86dff

Please sign in to comment.