From 7ed681532c07edbb3b04d7a05c8f1abf67508718 Mon Sep 17 00:00:00 2001 From: ozzy Date: Tue, 1 Sep 2026 16:57:02 -0500 Subject: [PATCH] feat(cli): add remove added "remove" and added check to prevent duplicate profiles --- src/cli.rs | 6 ++++++ src/main.rs | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/cli.rs b/src/cli.rs index 6f9b372..27477a9 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -12,6 +12,7 @@ pub enum Commands { List, Use(UseArgs), Add(AddArgs), + Remove(RemoveArgs), } #[derive(Debug, Args)] @@ -29,3 +30,8 @@ pub struct AddArgs { #[arg(long)] pub email: String, } + +#[derive(Debug, Args)] +pub struct RemoveArgs { + pub profile_name: String, +} diff --git a/src/main.rs b/src/main.rs index 5111f8d..6fcee4d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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") + } } }