feat(cli): add functionality to cli

added implementations of "add" "use" and "list"
This commit is contained in:
2026-09-01 16:47:46 -05:00
parent 029fc48b53
commit 2be76c5f65
6 changed files with 206 additions and 2 deletions
+46 -1
View File
@@ -1,8 +1,53 @@
use clap::Parser;
use crate::cli::Commands;
use crate::config::Profile;
mod cli;
mod config;
mod utils;
fn main() {
let args = cli::Cli::parse();
println!("{:?}", args);
match args.command {
Commands::List => {
let profiles = config::get_profile_list().expect("unable to get list of profiles");
if profiles.is_empty() {
println!("no profiles found");
return;
}
println!("{:<15} {:<20} {:<25}", "profile", "name", "email");
for profile in profiles {
println!(
"{:<15} {:<20} {:<25}",
profile.name, profile.username, profile.email
);
}
}
Commands::Use(args) => {
let profiles = config::get_profile_list().expect("unable to get list of profiles");
let profile = profiles.iter().find(|p| p.name == args.profile_name);
if profile.is_none() {
println!("profile not found");
return;
}
let profile = profile.unwrap();
let global = if args.global { "--global" } else { "" };
utils::run_command("git", &["config", "user.name", &profile.username, global]);
utils::run_command("git", &["config", "user.email", &profile.email, global]);
}
Commands::Add(args) => {
let mut profiles = config::get_profile_list().expect("unable to get list of profiles");
profiles.push(Profile {
name: args.profile_name,
username: args.name,
email: args.email,
});
config::write_profile_list(profiles).expect("unable to write profile file");
println!("profile added")
}
}
}