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
+15
View File
@@ -41,6 +41,11 @@ fn main() {
}
Commands::Add(args) => {
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 {
name: args.profile_name,
username: args.name,
@@ -49,5 +54,15 @@ fn main() {
config::write_profile_list(profiles).expect("unable to write profile file");
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")
}
}
}