feat(cli): add remove

added "remove" and added check to prevent duplicate profiles
This commit is contained in:
2026-09-01 16:57:02 -05:00
parent 2be76c5f65
commit 7ed681532c
2 changed files with 21 additions and 0 deletions
+6
View File
@@ -12,6 +12,7 @@ pub enum Commands {
List, List,
Use(UseArgs), Use(UseArgs),
Add(AddArgs), Add(AddArgs),
Remove(RemoveArgs),
} }
#[derive(Debug, Args)] #[derive(Debug, Args)]
@@ -29,3 +30,8 @@ pub struct AddArgs {
#[arg(long)] #[arg(long)]
pub email: String, pub email: String,
} }
#[derive(Debug, Args)]
pub struct RemoveArgs {
pub profile_name: String,
}
+15
View File
@@ -41,6 +41,11 @@ fn main() {
} }
Commands::Add(args) => { Commands::Add(args) => {
let mut profiles = config::get_profile_list().expect("unable to get list of profiles"); let mut profiles = config::get_profile_list().expect("unable to get list of profiles");
let existing_profile = profiles.iter().position(|p| p.name == args.profile_name);
if existing_profile.is_some() {
println!("profile already exists");
return;
}
profiles.push(Profile { profiles.push(Profile {
name: args.profile_name, name: args.profile_name,
username: args.name, username: args.name,
@@ -49,5 +54,15 @@ fn main() {
config::write_profile_list(profiles).expect("unable to write profile file"); config::write_profile_list(profiles).expect("unable to write profile file");
println!("profile added") println!("profile added")
} }
Commands::Remove(args) => {
let mut profiles = config::get_profile_list().expect("unable to get list of profiles");
let index = profiles
.iter()
.position(|p| p.name == args.profile_name)
.expect("unable to find profile");
profiles.remove(index);
config::write_profile_list(profiles).expect("unable to write profile file");
println!("profile removed")
}
} }
} }