add remove command (WIP)

master
Ales Katona 2 years ago
parent daa88e5bcb
commit 46789afafb
Signed by: almindor
GPG Key ID: 2F773149BF38B48F

@ -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

@ -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");

@ -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!(

@ -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<Vec<String>>,
},
}
@ -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 },

Loading…
Cancel
Save