Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Introduce new auth subcommand #4968

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions lib/cli/src/commands/auth/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
mod login;
mod logout;
mod whoami;

pub use login::*;
pub use logout::*;
pub use whoami::*;

use super::AsyncCliCommand;

/// Manage your .
#[derive(clap::Subcommand, Debug)]
pub enum CmdAuth {
Login(login::Login),
Logout(logout::Logout),
Whoami(whoami::Whoami),
}

#[async_trait::async_trait]
impl AsyncCliCommand for CmdAuth {
type Output = ();

async fn run_async(self) -> Result<Self::Output, anyhow::Error> {
match self {
CmdAuth::Login(l) => l.run_async().await,
CmdAuth::Logout(l) => l.run_async().await,
CmdAuth::Whoami(w) => w.run_async().await,
}
}
}
File renamed without changes.
23 changes: 16 additions & 7 deletions lib/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub mod ssh;
mod validate;
#[cfg(feature = "wast")]
mod wast;
mod whoami;
use colored::Colorize;
use std::env::args;
use tokio::task::JoinHandle;

Expand All @@ -51,7 +51,7 @@ pub use {create_obj::*, gen_c_header::*};
pub use self::journal::*;
pub use self::{
add::*, auth::*, cache::*, config::*, container::*, init::*, inspect::*, package::*,
publish::*, run::Run, self_update::*, validate::*, whoami::*,
publish::*, run::Run, self_update::*, validate::*,
};
use crate::error::PrettyError;

Expand Down Expand Up @@ -185,8 +185,12 @@ impl WasmerCmd {
Some(Cmd::Config(config)) => config.execute(),
Some(Cmd::Inspect(inspect)) => inspect.execute(),
Some(Cmd::Init(init)) => init.execute(),
Some(Cmd::Login(login)) => login.run(),
Some(Cmd::Logout(logout)) => logout.run(),
Some(Cmd::Login(login)) => {
let bin_name = std::env::args().nth(0).unwrap();
eprintln!("{}: The `{bin_name} login` command is superseded by `{bin_name} auth login` and will be removed in later versions.", "WARN".yellow().bold());
xdoardo marked this conversation as resolved.
Show resolved Hide resolved
login.run()
}
Some(Cmd::Auth(auth)) => auth.run(),
Some(Cmd::Publish(publish)) => publish.run().map(|_| ()),
Some(Cmd::Package(cmd)) => match cmd {
Package::Download(cmd) => cmd.execute(),
Expand All @@ -207,7 +211,12 @@ impl WasmerCmd {
Some(Cmd::Wast(wast)) => wast.execute(),
#[cfg(target_os = "linux")]
Some(Cmd::Binfmt(binfmt)) => binfmt.execute(),
Some(Cmd::Whoami(whoami)) => whoami.run(),
Some(Cmd::Whoami(whoami)) => {
let bin_name = std::env::args().nth(0).unwrap();
eprintln!("{}: The `{bin_name} whoami` command is superseded by `{bin_name} auth whoami` and will be removed in later versions.", "WARN".yellow().bold());
xdoardo marked this conversation as resolved.
Show resolved Hide resolved

whoami.run()
}
Some(Cmd::Add(install)) => install.execute(),

// Deploy commands.
Expand Down Expand Up @@ -290,8 +299,8 @@ enum Cmd {
/// Login into a wasmer.io-like registry
Login(Login),

/// Log out of the currently selected wasmer.io-like registry
Logout(Logout),
#[clap(subcommand)]
Auth(CmdAuth),

/// Publish a package to a registry [alias: package publish]
#[clap(name = "publish")]
Expand Down
Loading