-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: cli command for listing backends (#1989)
- Loading branch information
Showing
6 changed files
with
114 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use eyre::Result; | ||
|
||
use crate::forge::{self, ForgeType}; | ||
|
||
/// List built-in backends | ||
#[derive(Debug, clap::Args)] | ||
#[clap(visible_alias = "list", after_long_help = AFTER_LONG_HELP, verbatim_doc_comment)] | ||
pub struct BackendsLs {} | ||
|
||
impl BackendsLs { | ||
pub fn run(self) -> Result<()> { | ||
let mut forges = forge::list_forge_types(); | ||
forges.retain(|f| *f != ForgeType::Asdf); | ||
|
||
for forge in forges { | ||
miseprintln!("{}", forge); | ||
} | ||
Ok(()) | ||
} | ||
} | ||
|
||
static AFTER_LONG_HELP: &str = color_print::cstr!( | ||
r#"<bold><underline>Examples:</underline></bold> | ||
$ <bold>mise backends ls</bold> | ||
cargo | ||
go | ||
npm | ||
pipx | ||
ubi | ||
"# | ||
); | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
#[test] | ||
fn test_backends_list() { | ||
assert_cli_snapshot!("backends", "list"); | ||
} | ||
} |
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,32 @@ | ||
use clap::Subcommand; | ||
use eyre::Result; | ||
|
||
mod ls; | ||
|
||
#[derive(Debug, clap::Args)] | ||
#[clap(about = "Manage backends", visible_alias = "b", aliases = ["backend", "backend-list"])] | ||
pub struct Backends { | ||
#[clap(subcommand)] | ||
command: Option<Commands>, | ||
} | ||
|
||
#[derive(Debug, Subcommand)] | ||
enum Commands { | ||
Ls(ls::BackendsLs), | ||
} | ||
|
||
impl Commands { | ||
pub fn run(self) -> Result<()> { | ||
match self { | ||
Self::Ls(cmd) => cmd.run(), | ||
} | ||
} | ||
} | ||
|
||
impl Backends { | ||
pub fn run(self) -> Result<()> { | ||
let cmd = self.command.unwrap_or(Commands::Ls(ls::BackendsLs {})); | ||
|
||
cmd.run() | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/cli/backends/snapshots/mise__cli__backends__ls__tests__backends_list.snap
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,9 @@ | ||
--- | ||
source: src/cli/backends/ls.rs | ||
expression: output | ||
--- | ||
cargo | ||
go | ||
npm | ||
pipx | ||
ubi |
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