diff options
| author | David Lönnhager <david.l@mullvad.net> | 2023-05-19 13:10:57 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2023-05-22 09:47:40 +0200 |
| commit | 30b1234cf4e2d9a8ab257857fe0c2305f74a4d74 (patch) | |
| tree | cc7d2383d504ac041f2f1fa3acc1a703acbaff3f /mullvad-cli/src/cmds | |
| parent | b67a4bd7671e4c13292762e86f912a817f466df9 (diff) | |
| download | mullvadvpn-30b1234cf4e2d9a8ab257857fe0c2305f74a4d74.tar.xz mullvadvpn-30b1234cf4e2d9a8ab257857fe0c2305f74a4d74.zip | |
Use non-blocking I/O for account token input
Diffstat (limited to 'mullvad-cli/src/cmds')
| -rw-r--r-- | mullvad-cli/src/cmds/account.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/mullvad-cli/src/cmds/account.rs b/mullvad-cli/src/cmds/account.rs index d46469484f..7faf0856e1 100644 --- a/mullvad-cli/src/cmds/account.rs +++ b/mullvad-cli/src/cmds/account.rs @@ -65,7 +65,7 @@ impl Account { Account::Login { account } => { Self::login( &mut rpc, - account.unwrap_or_else(|| from_stdin("Enter an account number: ")), + unwrap_or_from_stdin(account, "Enter an account number: ").await, ) .await } @@ -217,6 +217,16 @@ async fn account_else_current( } } +async fn unwrap_or_from_stdin(val: Option<String>, prompt_str: &'static str) -> String { + if let Some(val) = val { + return val; + } + + tokio::task::spawn_blocking(|| from_stdin(prompt_str)) + .await + .unwrap() +} + fn from_stdin(prompt_str: &'static str) -> String { let mut val = String::new(); io::stdout() |
