From 01b179e93ba1ab94fef9b7109e242d165b060727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Katona?= Date: Sun, 31 Jul 2022 20:36:13 -0700 Subject: [PATCH] finish remove command support --- src/main.rs | 6 ++++++ src/vcs.rs | 21 ++++++++++++++++++++- src/vcs/cli.rs | 9 +++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index dd94d6a..ca69d5f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,6 +23,9 @@ fn main() { }; match args.command { + Commands::Cd { member } => { + todo!(); + } Commands::Checkout { reference, projects, @@ -30,6 +33,9 @@ fn main() { vcs.checkout_ref(&reference, projects) .expect("Error setting branch on projects"); } + Commands::Clone { url } => { + todo!(); + } Commands::Profile(ProfileCommand::Save { profile }) => { vcs.save_profile(&profile) .expect("Error saving vcs profile"); diff --git a/src/vcs.rs b/src/vcs.rs index b91cc46..bf323b0 100644 --- a/src/vcs.rs +++ b/src/vcs.rs @@ -240,7 +240,26 @@ impl Vcs { .as_table() .ok_or_else(|| Error::cargo_error("Cargo_vcs.toml is not a yaml table"))? .to_owned(); - // TODO + + if let Some(vcs_section) = vcs_main.get_mut("vcs") { + if let Some(vcs) = vcs_section.as_table_mut() { + if vcs.remove(profile_name).is_none() { + return Err(Error::project_error("Profile not found in toml file")); + } + } else { + return Err(Error::project_error("VCS subsection not a table")); + } + } else { + return Err(Error::project_error("VCS subsection missing in toml file")); + } + + let new_contents = toml::to_string(&vcs_main)?; + fs::write(vcs_path, new_contents)?; + + // remove from memory list too + self.profiles.retain(|p| p != profile_name); + + println!("Profile {} removed", profile_name.with(PROFILE_COLOR),); Ok(()) } diff --git a/src/vcs/cli.rs b/src/vcs/cli.rs index 304f45e..00acb0b 100644 --- a/src/vcs/cli.rs +++ b/src/vcs/cli.rs @@ -15,6 +15,15 @@ pub struct Cli { #[derive(Debug, Parser)] pub enum Commands { + /// Change directory into a specific member folder + Cd { + /// Workspace member name to change directory to + member: String, + }, + Clone { + /// Url to clone workspace from (e.g. ssh) + url: String, + }, /// Show workspace status Status { /// Show verbose status information