diff options
| author | Emīls <emils@mullvad.net> | 2021-03-10 12:31:28 +0000 |
|---|---|---|
| committer | Emīls <emils@mullvad.net> | 2021-03-17 13:44:55 +0000 |
| commit | ab5cb284d9c1675c25a2e2a38b448cba21b37336 (patch) | |
| tree | 185d14f93525f3c82116819109b22d687bad7085 /mullvad-cli/src/cmds | |
| parent | d394c5eaaf1b8b86f6f13d48dc9b6d3b20f655ce (diff) | |
| download | mullvadvpn-ab5cb284d9c1675c25a2e2a38b448cba21b37336.tar.xz mullvadvpn-ab5cb284d9c1675c25a2e2a38b448cba21b37336.zip | |
Enter account token from stdin
Diffstat (limited to 'mullvad-cli/src/cmds')
| -rw-r--r-- | mullvad-cli/src/cmds/account.rs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/mullvad-cli/src/cmds/account.rs b/mullvad-cli/src/cmds/account.rs index dbe2d2d817..803cabde00 100644 --- a/mullvad-cli/src/cmds/account.rs +++ b/mullvad-cli/src/cmds/account.rs @@ -1,8 +1,9 @@ use crate::{new_rpc_client, Command, Error, Result}; use clap::value_t_or_exit; +use itertools::Itertools; use mullvad_management_interface::{types::Timestamp, Code}; use mullvad_types::account::AccountToken; -use itertools::Itertools; +use std::io::{self, Write}; pub struct Account; @@ -22,7 +23,7 @@ impl Command for Account { .arg( clap::Arg::with_name("token") .help("The Mullvad account token to configure the client with") - .required(true), + .required(false), ), ) .subcommand( @@ -54,7 +55,20 @@ impl Command for Account { async fn run(&self, matches: &clap::ArgMatches<'_>) -> Result<()> { if let Some(set_matches) = matches.subcommand_matches("set") { - let mut token = value_t_or_exit!(set_matches.value_of("token"), String); + let mut token = match set_matches.value_of("token") { + Some(token) => token.to_string(), + None => { + let mut token = String::new(); + io::stdout() + .write_all(b"Enter account token: ") + .expect("Failed to write to STDOUT"); + let _ = io::stdout().flush(); + io::stdin() + .read_line(&mut token) + .expect("Failed to read from STDIN"); + token + } + }; token = token.split_whitespace().join("").to_string(); self.set(Some(token)).await } else if let Some(_matches) = matches.subcommand_matches("get") { |
