add profile list

master
Ales Katona 2 years ago
parent cb56f78583
commit fe9384abdf
Signed by: almindor
GPG Key ID: 2F773149BF38B48F

@ -35,6 +35,9 @@ fn main() {
vcs.set_profile(&profile) vcs.set_profile(&profile)
.expect("Error setting vcs profile"); .expect("Error setting vcs profile");
} }
Commands::Profile(ProfileCommand::List) => {
vcs.list_profiles().expect("Error setting vcs profile");
}
Commands::Status { verbose } => { Commands::Status { verbose } => {
if verbose { if verbose {
vcs.list(); vcs.list();

@ -146,7 +146,26 @@ impl Vcs {
min_msrv min_msrv
} }
pub fn save_profile(&self, profile_name: &str) -> Result<(), Error> { pub fn list_profiles(&self) -> Result<(), Error> {
let current_profile = self.current_profile()?;
let mut prefix = "";
print!("[");
for profile in &self.profiles {
if current_profile.as_ref() == Some(profile) {
print!("{}{}", prefix, profile.as_str().bold().with(PROFILE_COLOR));
} else {
print!("{}{}", prefix, profile.as_str().with(PROFILE_COLOR));
}
prefix = ", ";
}
println!("]");
Ok(())
}
pub fn save_profile(&mut self, profile_name: &str) -> Result<(), Error> {
let vcs_path = self.work_dir.join("Cargo_vcs.toml"); let vcs_path = self.work_dir.join("Cargo_vcs.toml");
let vcs = match fs::read_to_string(&vcs_path) { let vcs = match fs::read_to_string(&vcs_path) {
Ok(val) => toml::from_str(&val)?, Ok(val) => toml::from_str(&val)?,
@ -175,6 +194,10 @@ impl Vcs {
let new_contents = toml::to_string(&vcs_main)?; let new_contents = toml::to_string(&vcs_main)?;
fs::write(vcs_path, new_contents)?; fs::write(vcs_path, new_contents)?;
if !&self.profiles.iter().any(|p| p == profile_name) {
self.profiles.push(profile_name.into());
}
println!( println!(
"Workspace state saved as {}", "Workspace state saved as {}",
profile_name.with(PROFILE_COLOR), profile_name.with(PROFILE_COLOR),

@ -36,6 +36,8 @@ pub enum ProfileCommand {
/// Switch workspace to given profile /// Switch workspace to given profile
#[clap(arg_required_else_help = true)] #[clap(arg_required_else_help = true)]
Set { profile: String }, Set { profile: String },
/// Lists all saved profiles
List,
} }
#[derive(Debug, Parser)] #[derive(Debug, Parser)]

Loading…
Cancel
Save