This commit is contained in:
Felix Schütt
2022-11-11 11:43:08 +01:00
parent b798fe3f87
commit b8c281b1b5
2 changed files with 25 additions and 4 deletions

View File

@@ -16,9 +16,29 @@ impl Login {
fn get_token_or_ask_user(&self) -> Result<String, std::io::Error> {
match self.token.as_ref() {
Some(s) => Ok(s.clone()),
None => Input::new()
.with_prompt("Please paste the login token from https://wapm.io/me:\"")
.interact_text(),
None => {
let registry_host = url::Url::parse(&wasmer_registry::format_graphql(
&self.registry,
))
.map_err(|e| {
std::io::Error::new(
std::io::ErrorKind::Other,
format!("Invalid registry for login {}: {e}", self.registry),
)
})?;
let registry_host = registry_host.host_str().ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::Other,
format!("Invalid registry for login {}: no host", self.registry),
)
})?;
Input::new()
.with_prompt(&format!(
"Please paste the login token from https://{}/me:\"",
registry_host
))
.interact_text()
}
}
}