-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added registry command (#2147)
- Loading branch information
Showing
16 changed files
with
958 additions
and
795 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
Large diffs are not rendered by default.
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
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ source: src/cli/backends/ls.rs | |
expression: output | ||
--- | ||
cargo | ||
core | ||
go | ||
npm | ||
pipx | ||
|
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,78 @@ | ||
use std::collections::BTreeMap; | ||
|
||
use eyre::Result; | ||
use tabled::{Table, Tabled}; | ||
|
||
use crate::config::{settings, Config}; | ||
use crate::registry::REGISTRY; | ||
use crate::ui::table; | ||
|
||
/// [experimental] List available tools | ||
#[derive(Debug, clap::Args)] | ||
#[clap(after_long_help = AFTER_LONG_HELP, verbatim_doc_comment)] | ||
pub struct Registry {} | ||
|
||
impl Registry { | ||
pub fn run(self) -> Result<()> { | ||
settings::ensure_experimental("registry")?; | ||
let mut tools = BTreeMap::new(); | ||
|
||
for (plugin, url) in Config::get().get_shorthands() { | ||
let re = regex!(r#"^https://github.com/(.+?/.+?)(.git)?$"#); | ||
let full = if let Some(caps) = re.captures(url) { | ||
format!("asdf:{}", &caps[1]) | ||
} else { | ||
format!("asdf:{}", url) | ||
}; | ||
tools.insert(plugin.to_string(), full); | ||
} | ||
|
||
for (short, full) in REGISTRY.iter() { | ||
tools.insert(short.to_string(), full.to_string()); | ||
} | ||
|
||
let data = tools.into_iter().map(|x| x.into()).collect::<Vec<Row>>(); | ||
let mut table = Table::new(data); | ||
table::default_style(&mut table, false); | ||
miseprintln!("{table}"); | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(Tabled, Eq, PartialEq, Ord, PartialOrd)] | ||
#[tabled(rename_all = "PascalCase")] | ||
struct Row { | ||
short: String, | ||
full: String, | ||
} | ||
|
||
impl From<(String, String)> for Row { | ||
fn from((short, full): (String, String)) -> Self { | ||
Self { short, full } | ||
} | ||
} | ||
|
||
static AFTER_LONG_HELP: &str = color_print::cstr!( | ||
r#"<bold><underline>Examples:</underline></bold> | ||
$ <bold>mise registry</bold> | ||
node core:node | ||
poetry asdf:mise-plugins/mise-poetry | ||
ubi cargo:ubi | ||
"# | ||
); | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use test_log::test; | ||
|
||
use crate::cli::tests::grep; | ||
use crate::test::reset; | ||
|
||
#[test] | ||
fn test_registry() { | ||
reset(); | ||
let out = assert_cli!("registry"); | ||
assert_snapshot!(grep(out, "node"), @"node core:node"); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,18 @@ | ||
pub const REGISTRY: &[(&str, &str)] = &[ | ||
use std::collections::BTreeMap; | ||
|
||
use once_cell::sync::Lazy; | ||
|
||
use crate::plugins::core::CORE_PLUGINS; | ||
|
||
const _REGISTRY: &[(&str, &str)] = &[ | ||
("ubi", "cargo:ubi"), | ||
// ("elixir", "asdf:mise-plugins/mise-elixir"), | ||
]; | ||
|
||
pub static REGISTRY: Lazy<BTreeMap<&str, String>> = Lazy::new(|| { | ||
let core = CORE_PLUGINS | ||
.iter() | ||
.map(|p| (p.name(), format!("core:{}", p.name()))); | ||
let registry = _REGISTRY.iter().map(|(k, v)| (*k, v.to_string())); | ||
core.chain(registry).collect() | ||
}); |
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