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> { fn get_token_or_ask_user(&self) -> Result<String, std::io::Error> {
match self.token.as_ref() { match self.token.as_ref() {
Some(s) => Ok(s.clone()), Some(s) => Ok(s.clone()),
None => Input::new() None => {
.with_prompt("Please paste the login token from https://wapm.io/me:\"") let registry_host = url::Url::parse(&wasmer_registry::format_graphql(
.interact_text(), &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()
}
} }
} }

View File

@@ -8,7 +8,8 @@ pub mod graphql;
pub mod login; pub mod login;
pub mod utils; pub mod utils;
use crate::config::{format_graphql, Registries}; pub use crate::config::format_graphql;
use crate::config::Registries;
pub use config::PartialWapmConfig; pub use config::PartialWapmConfig;
pub static GLOBAL_CONFIG_FILE_NAME: &str = if cfg!(target_os = "wasi") { pub static GLOBAL_CONFIG_FILE_NAME: &str = if cfg!(target_os = "wasi") {