From 2806fe9cd55161546f5a88f2be77f9186f612e0f Mon Sep 17 00:00:00 2001 From: Edoardo Marangoni Date: Mon, 29 Jul 2024 17:18:41 +0200 Subject: [PATCH 1/2] feat(cli/auth): Introduce new `auth` subcommand --- lib/cli/src/commands/auth/mod.rs | 25 +++++++++++++++++++++++ lib/cli/src/commands/{ => auth}/whoami.rs | 0 lib/cli/src/commands/mod.rs | 23 ++++++++++++++------- 3 files changed, 41 insertions(+), 7 deletions(-) rename lib/cli/src/commands/{ => auth}/whoami.rs (100%) diff --git a/lib/cli/src/commands/auth/mod.rs b/lib/cli/src/commands/auth/mod.rs index 803413214b8..b8937535187 100644 --- a/lib/cli/src/commands/auth/mod.rs +++ b/lib/cli/src/commands/auth/mod.rs @@ -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 { + match self { + CmdAuth::Login(l) => l.run_async().await, + CmdAuth::Logout(l) => l.run_async().await, + CmdAuth::Whoami(w) => w.run_async().await, + } + } +} diff --git a/lib/cli/src/commands/whoami.rs b/lib/cli/src/commands/auth/whoami.rs similarity index 100% rename from lib/cli/src/commands/whoami.rs rename to lib/cli/src/commands/auth/whoami.rs diff --git a/lib/cli/src/commands/mod.rs b/lib/cli/src/commands/mod.rs index 42f40ed918a..d186dc8653d 100644 --- a/lib/cli/src/commands/mod.rs +++ b/lib/cli/src/commands/mod.rs @@ -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; @@ -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; @@ -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()); + 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(), @@ -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()); + + whoami.run() + } Some(Cmd::Add(install)) => install.execute(), // Deploy commands. @@ -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")] From a3f8bb482ef97f08c5c2d85b510b3ddfef5a2efa Mon Sep 17 00:00:00 2001 From: Edoardo Marangoni Date: Tue, 30 Jul 2024 16:32:16 +0200 Subject: [PATCH 2/2] fix(cli/auth): Remove deprecation warnings from `login` and `whoami` --- lib/cli/src/commands/mod.rs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/lib/cli/src/commands/mod.rs b/lib/cli/src/commands/mod.rs index d186dc8653d..07b0706b7e1 100644 --- a/lib/cli/src/commands/mod.rs +++ b/lib/cli/src/commands/mod.rs @@ -31,7 +31,6 @@ pub mod ssh; mod validate; #[cfg(feature = "wast")] mod wast; -use colored::Colorize; use std::env::args; use tokio::task::JoinHandle; @@ -185,11 +184,7 @@ impl WasmerCmd { Some(Cmd::Config(config)) => config.execute(), Some(Cmd::Inspect(inspect)) => inspect.execute(), Some(Cmd::Init(init)) => init.execute(), - 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()); - login.run() - } + Some(Cmd::Login(login)) => login.run(), Some(Cmd::Auth(auth)) => auth.run(), Some(Cmd::Publish(publish)) => publish.run().map(|_| ()), Some(Cmd::Package(cmd)) => match cmd { @@ -211,12 +206,7 @@ impl WasmerCmd { Some(Cmd::Wast(wast)) => wast.execute(), #[cfg(target_os = "linux")] Some(Cmd::Binfmt(binfmt)) => binfmt.execute(), - 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()); - - whoami.run() - } + Some(Cmd::Whoami(whoami)) => whoami.run(), Some(Cmd::Add(install)) => install.execute(), // Deploy commands.