aboutsummaryrefslogtreecommitdiffstats
path: root/src/command/register.rs
diff options
context:
space:
mode:
authorJannik <jannik.peters@posteo.de>2021-09-24 18:24:59 +0200
committerGitHub <noreply@github.com>2021-09-24 16:24:59 +0000
commit27d3d81afe3021e226b80a2c7734ed9a8c595641 (patch)
tree577b6cf9f1db033c3a68124d6a5ce01d0a8d7a83 /src/command/register.rs
parentResolve clippy warnings (#187) (diff)
downloadatuin-27d3d81afe3021e226b80a2c7734ed9a8c595641.zip
feat: allow input of credentials from stdin (#185)
* feat: allow credential input from stdin for registration This changes the options for register to be optional. If arguments are not given, the program will ask for them interactively. * feat: allow credential input from stdin for login * style: apply cargo fmt
Diffstat (limited to 'src/command/register.rs')
-rw-r--r--src/command/register.rs48
1 files changed, 43 insertions, 5 deletions
diff --git a/src/command/register.rs b/src/command/register.rs
index 7c38f483..c242e8ab 100644
--- a/src/command/register.rs
+++ b/src/command/register.rs
@@ -1,4 +1,5 @@
use std::fs::File;
+use std::io;
use std::io::prelude::*;
use eyre::Result;
@@ -11,17 +12,54 @@ use atuin_client::settings::Settings;
#[structopt(setting(structopt::clap::AppSettings::DeriveDisplayOrder))]
pub struct Cmd {
#[structopt(long, short)]
- pub username: String,
+ pub username: Option<String>,
#[structopt(long, short)]
- pub email: String,
+ pub email: Option<String>,
#[structopt(long, short)]
- pub password: String,
+ pub password: Option<String>,
}
-pub fn run(settings: &Settings, username: &str, email: &str, password: &str) -> Result<()> {
- let session = api_client::register(settings.sync_address.as_str(), username, email, password)?;
+fn get_input() -> Result<String> {
+ let mut input = String::new();
+ io::stdin().read_line(&mut input)?;
+ Ok(input.trim_end_matches(&['\r', '\n'][..]).to_string())
+}
+
+pub fn run(
+ settings: &Settings,
+ username: Option<String>,
+ email: Option<String>,
+ password: Option<String>,
+) -> Result<()> {
+ let username = if let Some(username) = username {
+ username
+ } else {
+ eprint!("Please enter username: ");
+ get_input().expect("Failed to read username from input")
+ };
+
+ let email = if let Some(email) = email {
+ email
+ } else {
+ eprint!("Please enter email: ");
+ get_input().expect("Failed to read email from input")
+ };
+
+ let password = if let Some(password) = password {
+ password
+ } else {
+ eprint!("Please enter password: ");
+ get_input().expect("Failed to read password from input")
+ };
+
+ let session = api_client::register(
+ settings.sync_address.as_str(),
+ username.as_str(),
+ email.as_str(),
+ password.as_str(),
+ )?;
let path = settings.session_path.as_str();
let mut file = File::create(path)?;