aboutsummaryrefslogtreecommitdiffstats
path: root/src/command/login.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/command/login.rs')
-rw-r--r--src/command/login.rs41
1 files changed, 35 insertions, 6 deletions
diff --git a/src/command/login.rs b/src/command/login.rs
index 9be98e23..57d99009 100644
--- a/src/command/login.rs
+++ b/src/command/login.rs
@@ -1,3 +1,4 @@
+use std::io;
use std::io::prelude::*;
use std::{borrow::Cow, fs::File};
@@ -12,13 +13,19 @@ 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 password: String,
+ pub password: Option<String>,
#[structopt(long, short, about = "the encryption key for your account")]
- pub key: String,
+ pub key: Option<String>,
+}
+
+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())
}
impl Cmd {
@@ -33,11 +40,33 @@ impl Cmd {
return Ok(());
}
+ // TODO: Maybe get rid of clone
+ let username = if let Some(username) = self.username.clone() {
+ username
+ } else {
+ eprint!("Please enter username: ");
+ get_input().expect("Failed to read username from input")
+ };
+
+ let password = if let Some(password) = self.password.clone() {
+ password
+ } else {
+ eprint!("Please enter password: ");
+ get_input().expect("Failed to read email from input")
+ };
+
+ let key = if let Some(key) = self.key.clone() {
+ key
+ } else {
+ eprint!("Please enter encryption key: ");
+ get_input().expect("Failed to read password from input")
+ };
+
let session = api_client::login(
settings.sync_address.as_str(),
LoginRequest {
- username: Cow::Borrowed(&self.username),
- password: Cow::Borrowed(&self.password),
+ username: Cow::Borrowed(&username),
+ password: Cow::Borrowed(&password),
},
)?;
@@ -47,7 +76,7 @@ impl Cmd {
let key_path = settings.key_path.as_str();
let mut file = File::create(key_path)?;
- file.write_all(self.key.as_bytes())?;
+ file.write_all(key.as_bytes())?;
println!("Logged in!");