-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3297: Implement wasmer login r=fschutt a=fschutt Co-authored-by: Felix Schütt <[email protected]> Co-authored-by: Felix Schütt <[email protected]>
- Loading branch information
Showing
14 changed files
with
957 additions
and
441 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use clap::Parser; | ||
use dialoguer::Input; | ||
|
||
/// Subcommand for listing packages | ||
#[derive(Debug, Clone, Parser)] | ||
pub struct Login { | ||
/// Registry to log into (default: wapm.io) | ||
#[clap(long, default_value = "wapm.io")] | ||
pub registry: String, | ||
/// Login token | ||
#[clap(name = "TOKEN")] | ||
pub token: Option<String>, | ||
} | ||
|
||
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 => { | ||
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() | ||
} | ||
} | ||
} | ||
|
||
/// execute [List] | ||
pub fn execute(&self) -> Result<(), anyhow::Error> { | ||
let token = self.get_token_or_ask_user()?; | ||
wasmer_registry::login::login_and_save_token(&self.registry, &token) | ||
.map_err(|e| anyhow::anyhow!("{e}")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
query WhoAmIQuery { | ||
viewer { | ||
username | ||
} | ||
} |
Oops, something went wrong.