From 13c89c1896867eb01bb5f8d0e1b52e78ae1066b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=B3=E5=85=89=E5=B0=91=E5=B9=B4?= <849317537@qq.com> Date: Tue, 30 Jul 2024 10:51:45 +0000 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/error.rs | 2 +- src/main.rs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/error.rs b/src/error.rs index 51eeb6f..843bc91 100644 --- a/src/error.rs +++ b/src/error.rs @@ -21,7 +21,7 @@ impl Display for RockerError { Self::IoError(e) => write!(f, "{}", e), Self::OtherError(s) => write!(f, "{}", s), Self::ErrnoError(e) => write!(f, "{}", e), - Self::TomlSerError(e) => write!(f, "{}", e) + Self::TomlSerError(e) => write!(f, "{}", e), Self::TomlDeError(e) => write!(f, "{}", e) } } diff --git a/src/main.rs b/src/main.rs index f6d1b27..9408542 100644 --- a/src/main.rs +++ b/src/main.rs @@ -227,7 +227,7 @@ fn run_container(cmd: &String, wait:bool, log:bool, volume_path: &PathBuf) -> Re } // 初始化容器工作目录 - let _container_id = uuid::Uuid::new_v4().to_string(); + let _container_id = uuid::Uuid::new_v4().to_string()[0..8].to_string(); let container_work_path = Path::new(WORKSPACE).join("containers").join(&_container_id); let container_upper_path = container_work_path.join("upper"); let container_merged_path = container_work_path.join("merged"); @@ -290,8 +290,8 @@ struct ContainerInfo { id: String, run: String, image: String, - volume: Option, - env: Option, + volume: String, + env: String, } fn save_container_info(args: &RockerArgs, container_id: &String) -> Result<()> { @@ -300,8 +300,8 @@ fn save_container_info(args: &RockerArgs, container_id: &String) -> Result<()> { id: container_id.clone(), run: args.run.as_ref().unwrap().clone(), image: args.image.as_ref().unwrap().clone(), - volume: None, - env: None + volume: "".to_string(), + env: "".to_string() }; let toml_str = toml::to_string(&container_info)?; fs::write(container_info_path, toml_str)?; @@ -312,13 +312,13 @@ fn save_container_info(args: &RockerArgs, container_id: &String) -> Result<()> { fn show_containers() -> Result<()> { let containers_path = Path::new(WORKSPACE).join("containers"); - println!("{}{}{}{}{}", "id", "image", "run", "volume", "env"); + println!("{:<20}{:<20}{:<20}{:<20}{:<20}", "id", "image", "run", "volume", "env"); for entry in fs::read_dir(containers_path)? { let path = entry?.path(); let info_path = path.join("info.toml"); let info_str = fs::read_to_string(info_path)?; let container_info: ContainerInfo = toml::from_str(&info_str)?; - println!("{}{}{}{:?}{:?}", container_info.id, container_info.image, container_info.run, container_info.volume, container_info.env); + println!("{:<20}{:<20}{:<20}{:<20}{:<20}", container_info.id, container_info.image, container_info.run, &container_info.volume[0..20], &container_info.env[0..20]); } Ok(()) }