main
阳光少年 1 year ago
parent 66aeab6753
commit 57419f6662

@ -56,7 +56,7 @@ struct RockerArgs {
// rm container_id
#[arg(long)]
rm: Option<Vec<String>>
rm: Option<String>
}
@ -151,7 +151,7 @@ fn init_container_custom_volume<P: AsRef<Path>>(container_merged_path: P, custom
let container_path = container_path_buf.to_string_lossy().to_string();
// 创建宿主机和容器内的目录
create_dir(Path::new(host_path), false)?;
create_dir(Path::new(host_path), true)?;
create_dir(&container_path, true)?;
// 绑定
@ -386,7 +386,7 @@ impl Display for ContainerInfo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let volume: String = self.volume.chars().take(20).collect();
let env: String = self.env.chars().take(20).collect();
write!(f, "\x1b[4m{:<10}{:<8}{:<10}{:<20}{:<20}{:<20}{:<10}\x1b[24m", self.id, self.pid, self.image, self.run, volume, env, &self.status)
write!(f, "\x1b[4m{:<10} {:<8} {:<10} {:<20} {:<20} {:<20} {:<10}\x1b[24m", self.id, self.pid, self.image, self.run, volume, env, &self.status)
}
}
@ -397,7 +397,7 @@ fn save_container_info(args: &RockerArgs, container_id: &String, pid: i32) -> Re
pid: pid,
run: args.run.as_ref().unwrap().clone(),
image: args.image.as_ref().unwrap().clone(),
volume: "".to_string(),
volume: args.volume.clone().unwrap_or("".to_string()),
env: "".to_string(),
status: ContainerStatus::READY,
};
@ -406,7 +406,7 @@ fn save_container_info(args: &RockerArgs, container_id: &String, pid: i32) -> Re
Ok(())
}
fn get_container_info(container_id: &String) -> Result<ContainerInfo> {
fn get_container_info(container_id: &str) -> Result<ContainerInfo> {
let container_work_path = Path::new(WORKSPACE).join("containers").join(container_id);
let container_info_path = container_work_path.join(INFO_FILE);
let lock_path = container_work_path.join(LOCK_FILE);
@ -436,14 +436,14 @@ fn get_all_container_info() -> Result<Vec<ContainerInfo>> {
.map(|res| res.map(|e| e.file_name()))
.filter_map(|p| p.ok())
.map(|f|f.to_string_lossy().to_string())
.filter_map(|s|get_container_info(&s).ok())
.filter_map(|s|get_container_info(s.as_str()).ok())
.collect::<Vec<ContainerInfo>>();
Ok(all_containers_info)
}
/// 读取所有容器的状态
fn show_containers(is_show_all: bool) -> Result<()> {
println!("{:<10}{:<8}{:<10}{:<20}{:<20}{:<20}{:<10}", "id", "pid", "image", "run", "volume", "env", "status");
println!("{:<10} {:<8} {:<10} {:<20} {:<20} {:<20} {:<10}", "id", "pid", "image", "run", "volume", "env", "status");
for container_info in get_all_container_info()? {
if is_show_all{
println!("{container_info}");
@ -454,8 +454,8 @@ fn show_containers(is_show_all: bool) -> Result<()> {
Ok(())
}
fn delete_container(containers_id: &Vec<String>) -> Result<()> {
for container_id in containers_id {
fn delete_container(containers_id: &str) -> Result<()> {
for container_id in containers_id.split(",") {
if let Ok(container_info) = get_container_info(container_id) {
let container_work_path = Path::new(WORKSPACE).join("containers").join(container_id);
let container_merged_path = container_work_path.join("merged");

Loading…
Cancel
Save