diff --git a/README.md b/README.md index 423ca64..3685ec7 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ e310x-hal: refs/heads/e-h-1.0.0-alpha.7 [.../rust/embedded/e310/e310x-hal] ### Switch to a branch or commit on workspace members - `cargo vcs checkout master` - switch to master on all workspace members -- `cargo vcs checkout master -p one_project` - switch on specific member only +- `cargo vcs checkout master -m member1, member2` - switch on specific members only ``` $ cargo vcs checkout master redv set to refs/heads/master diff --git a/src/main.rs b/src/main.rs index fc992fc..dd94d6a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,6 +34,10 @@ fn main() { vcs.save_profile(&profile) .expect("Error saving vcs profile"); } + Commands::Profile(ProfileCommand::Remove { profile }) => { + vcs.remove_profile(&profile) + .expect("Error removing vcs profile"); + } Commands::Profile(ProfileCommand::Set { profile }) => { vcs.set_profile(&profile) .expect("Error setting vcs profile"); diff --git a/src/vcs.rs b/src/vcs.rs index 99da7f1..b91cc46 100644 --- a/src/vcs.rs +++ b/src/vcs.rs @@ -221,6 +221,30 @@ impl Vcs { Ok(()) } + pub fn remove_profile(&mut self, profile_name: &str) -> Result<(), Error> { + if !self.profiles.contains(&String::from(profile_name)) { + eprintln!( + "{}{}", + "Profile not found: ".with(ERROR_COLOR), + profile_name.with(PROFILE_COLOR) + ); + return Ok(()); + } + + let vcs_path = self.work_dir.join("Cargo_vcs.toml"); + let vcs: toml::Value = match fs::read_to_string(&vcs_path) { + Ok(val) => toml::from_str(&val)?, + Err(err) => return Err(err.into()), + }; + let mut vcs_main = vcs + .as_table() + .ok_or_else(|| Error::cargo_error("Cargo_vcs.toml is not a yaml table"))? + .to_owned(); + // TODO + + Ok(()) + } + pub fn set_profile(&mut self, profile_name: &str) -> Result<(), Error> { if !self.profiles.contains(&String::from(profile_name)) { eprintln!( diff --git a/src/vcs/cli.rs b/src/vcs/cli.rs index 2a2946f..304f45e 100644 --- a/src/vcs/cli.rs +++ b/src/vcs/cli.rs @@ -28,8 +28,8 @@ pub enum Commands { Checkout { /// Reference name reference: String, - /// Project list to apply checkout to, defaults to all - #[clap(short = 'p')] + /// Memeber list to apply checkout to, defaults to all + #[clap(short = 'm')] projects: Option>, }, } @@ -39,6 +39,9 @@ pub enum ProfileCommand { /// Save the current workspace VCS state to Cargo_vcs.toml under given profile name #[clap(arg_required_else_help = true)] Save { profile: String }, + /// Remove the given profile configuration + #[clap(arg_required_else_help = true)] + Remove { profile: String }, /// Switch workspace to given profile #[clap(arg_required_else_help = true)] Set { profile: String },