Skip to content

Commit

Permalink
config/users: take parameters from command line
Browse files Browse the repository at this point in the history
GitHub issue:
#173

The arguments provided with --username and --password were
not being used.
  • Loading branch information
jasonish committed May 17, 2021
1 parent 89f46cf commit 55b3e79
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/commands/config/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,28 @@ fn get_input(prompt: &str) -> Result<String> {

fn add(args: &clap::ArgMatches) -> Result<()> {
let repo = open_config_repo(args.value_of("data-directory"))?;
let username = get_input("Username: ")?;

let username = if let Some(username) = args.value_of("username") {
username.to_string()
} else {
get_input("Username: ")?
};
if username.is_empty() {
return Err(anyhow!("empty username not allowed"));
}
let password = rpassword::read_password_from_tty(Some("Password: "))?;
if password.is_empty() {
return Err(anyhow!("empty password not allowed"));
}
let confirm = rpassword::read_password_from_tty(Some("Confirm password: "))?;
if password != confirm {
return Err(anyhow!("passwords to not match"));
}

let password = if let Some(password) = args.value_of("password") {
password.to_string()
} else {
// Yes, we're allowing empty passwords.
let password = rpassword::read_password_from_tty(Some("Password: "))?;
let confirm = rpassword::read_password_from_tty(Some("Confirm password: "))?;
if password != confirm {
return Err(anyhow!("passwords to not match"));
}
password
};

repo.add_user(&username, &password)?;
println!("User added: username=\"{}\"", username);
Ok(())
Expand Down

0 comments on commit 55b3e79

Please sign in to comment.