Skip to content

Commit f0f388a

Browse files
committed
Use latest rpassword, added --stdin flag
1 parent 5a1b2ec commit f0f388a

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tmc-langs-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dirs = "4.0.0"
1919
env_logger = "0.9.0"
2020
log = "0.4.14"
2121
quit = "1.1.4"
22-
rpassword = "5.0.1"
22+
rpassword = "7.0.0"
2323
schemars = "0.8.8"
2424
serde = "1.0.136"
2525
serde_json = "1.0.78"

tmc-langs-cli/src/app.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,10 @@ pub enum Core {
393393
/// The OAUTH2 access token that should be used for authentication.
394394
#[clap(long, required_unless_present = "email")]
395395
set_access_token: Option<String>,
396+
/// If set, the password will be read from stdin instead of TTY like usual.
397+
/// The keyboard input is not hidden in this case, so this should only be used when running the CLI programmatically.
398+
#[clap(long)]
399+
stdin: bool,
396400
},
397401

398402
/// Logs out and removes the OAuth2 token from config

tmc-langs-cli/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::{
2020
collections::HashMap,
2121
env,
2222
fs::File,
23-
io::{self, Cursor, Read, Write},
23+
io::{self, Cursor, Read, Write, BufReader},
2424
ops::Deref,
2525
path::{Path, PathBuf},
2626
};
@@ -804,13 +804,19 @@ fn run_core_inner(
804804
base64,
805805
email,
806806
set_access_token,
807+
stdin,
807808
} => {
808809
// get token from argument or server
809810
let token = if let Some(token) = set_access_token {
810811
tmc_langs::login_with_token(token)
811812
} else if let Some(email) = email {
812813
// TODO: print "Please enter password" and add "quiet" flag
813-
let password = rpassword::read_password().context("Failed to read password")?;
814+
let password = if stdin {
815+
let mut stdin = BufReader::new(std::io::stdin());
816+
rpassword::read_password_from_bufread(&mut stdin).context("Failed to read password")?
817+
} else {
818+
rpassword::read_password().context("Failed to read password")?
819+
};
814820
let decoded = if base64 {
815821
let bytes = base64::decode(password)?;
816822
String::from_utf8(bytes).context("Failed to decode password with base64")?

tmc-langs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ md5 = "0.7.0"
2424
oauth2 = { version = "4.0.0-beta.1", features = ["reqwest"] }
2525
once_cell = "1.9.0"
2626
regex = "1.5.4"
27-
rpassword = "5.0.1"
27+
rpassword = "7.0.0"
2828
schemars = "0.8.8"
2929
serde = { version = "1.0.136", features = ["derive"] }
3030
serde_json = "1.0.78"

0 commit comments

Comments
 (0)