feat(cli): add "current"
allow viewing of current git user todo: clean up the awful code in main
This commit is contained in:
+34
-3
@@ -35,9 +35,17 @@ fn main() {
|
||||
}
|
||||
|
||||
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]);
|
||||
|
||||
utils::run_command(
|
||||
"git",
|
||||
&add_global_if(&["config", "user.name", &profile.username], args.global),
|
||||
)
|
||||
.expect("command failed");
|
||||
utils::run_command(
|
||||
"git",
|
||||
&add_global_if(&["config", "user.email", &profile.email], args.global),
|
||||
)
|
||||
.expect("command failed");
|
||||
}
|
||||
Commands::Add(args) => {
|
||||
let mut profiles = config::get_profile_list().expect("unable to get list of profiles");
|
||||
@@ -64,5 +72,28 @@ fn main() {
|
||||
config::write_profile_list(profiles).expect("unable to write profile file");
|
||||
println!("profile removed")
|
||||
}
|
||||
Commands::Current(args) => {
|
||||
let mut name =
|
||||
utils::run_command("git", &add_global_if(&["config", "user.name"], args.global))
|
||||
.expect("command failed");
|
||||
let mut email = utils::run_command(
|
||||
"git",
|
||||
&add_global_if(&["config", "user.email"], args.global),
|
||||
)
|
||||
.expect("command failed");
|
||||
|
||||
name.pop();
|
||||
email.pop();
|
||||
|
||||
println!("current user: {} ({})", name, email);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn add_global_if<'a>(args: &[&'a str], global: bool) -> Vec<&'a str> {
|
||||
let mut result = args.to_vec();
|
||||
if global {
|
||||
result.insert(1, "--global");
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user