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(()) }