Skip to content

Commit

Permalink
feat: accept argument for mise registry (#2841)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx authored Oct 27, 2024
1 parent 6ef2062 commit c52be46
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 38 deletions.
2 changes: 1 addition & 1 deletion docs/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Answer yes to all confirmation prompts
* [`mise plugins uninstall [-p --purge] [-a --all] [PLUGIN]...`](/cli/plugins/uninstall.md)
* [`mise plugins update [-j --jobs <JOBS>] [PLUGIN]...`](/cli/plugins/update.md)
* [`mise prune [FLAGS] [PLUGIN]...`](/cli/prune.md)
* [`mise registry`](/cli/registry.md)
* [`mise registry [NAME]`](/cli/registry.md)
* [`mise reshim [-f --force]`](/cli/reshim.md)
* [`mise run [FLAGS]`](/cli/run.md)
* [`mise self-update [FLAGS] [VERSION]`](/cli/self-update.md)
Expand Down
13 changes: 11 additions & 2 deletions docs/cli/registry.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
# `mise registry`

**Usage**: `mise registry`
**Usage**: `mise registry [NAME]`

[experimental] List available tools to install
List available tools to install

This command lists the tools available in the registry as shorthand names.

For example, `poetry` is shorthand for `asdf:mise-plugins/mise-poetry`.

## Arguments

### `[NAME]`

Show only the specified tool's full name

Examples:

$ mise registry
node core:node
poetry asdf:mise-plugins/mise-poetry
ubi cargo:ubi-cli

$ mise registry poetry
asdf:mise-plugins/mise-poetry
4 changes: 4 additions & 0 deletions e2e/cli/test_registry
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

assert "mise registry gh" "ubi:cli/cli[exe=gh]"
assert_contains "mise registry" "gh ubi:cli/cli[exe=gh]"
2 changes: 1 addition & 1 deletion man/man1/mise.1
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ mise\-prune(1)
Delete unused versions of tools
.TP
mise\-registry(1)
[experimental] List available tools to install
List available tools to install
.TP
mise\-reshim(1)
Creates new shims based on bin paths from currently installed tools.
Expand Down
8 changes: 6 additions & 2 deletions mise.usage.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -825,8 +825,8 @@ as will versions only referenced on the command line `mise exec <PLUGIN>@<VERSIO
flag "--tools" help="Prune only unused versions of tools"
arg "[PLUGIN]..." help="Prune only versions from this plugin(s)" var=true
}
cmd "registry" help="[experimental] List available tools to install" {
long_help r"[experimental] List available tools to install
cmd "registry" help="List available tools to install" {
long_help r"List available tools to install

This command lists the tools available in the registry as shorthand names.

Expand All @@ -837,7 +837,11 @@ For example, `poetry` is shorthand for `asdf:mise-plugins/mise-poetry`."
node core:node
poetry asdf:mise-plugins/mise-poetry
ubi cargo:ubi-cli

$ mise registry poetry
asdf:mise-plugins/mise-poetry
"
arg "[NAME]" help="Show only the specified tool's full name"
}
cmd "reshim" help="Creates new shims based on bin paths from currently installed tools." {
long_help r#"Creates new shims based on bin paths from currently installed tools.
Expand Down
4 changes: 2 additions & 2 deletions settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ docs = """
The age of the cache before it is considered stale. mise will occasionally delete cache files which
have not been accessed in this amount of time.
Set to `0` to keep cache files indefinitely.
Set to `0s` to keep cache files indefinitely.
"""

[cargo.binstall]
Expand Down Expand Up @@ -302,7 +302,7 @@ for example, `.nvmrc` in the case of node's nvm. See [legacy version files](#leg
for more
information.
Set to "0" to disable legacy version file parsing.
Set to "false" to disable legacy version file parsing.
"""

[legacy_version_file_disable_tools]
Expand Down
48 changes: 22 additions & 26 deletions src/cli/registry.rs
Original file line number Diff line number Diff line change
@@ -1,44 +1,37 @@
use std::collections::BTreeMap;

use crate::config::{settings, Config};
use crate::registry::REGISTRY;
use crate::ui::table;
use eyre::Result;
use eyre::{bail, Result};
use tabled::{Table, Tabled};
use xx::regex;

/// [experimental] List available tools to install
/// List available tools to install
///
/// This command lists the tools available in the registry as shorthand names.
///
/// For example, `poetry` is shorthand for `asdf:mise-plugins/mise-poetry`.
#[derive(Debug, clap::Args)]
#[clap(after_long_help = AFTER_LONG_HELP, verbatim_doc_comment)]
pub struct Registry {}
pub struct Registry {
/// Show only the specified tool's full name
name: Option<String>,
}

impl Registry {
pub fn run(self) -> Result<()> {
settings::ensure_experimental("registry")?;
let mut tools = BTreeMap::new();

let re = regex!(r#"^https://github.com/(.+?/.+?)(.git)?$"#);
for (plugin, url) in Config::get().get_shorthands() {
let full = if let Some(caps) = re.captures(url) {
format!("asdf:{}", &caps[1])
if let Some(name) = &self.name {
if let Some(full) = REGISTRY.get(name.as_str()) {
miseprintln!("{full}");
} else {
format!("asdf:{}", url)
};
tools.insert(plugin.to_string(), full);
bail!("tool not found in registry: {name}");
}
} else {
let data = REGISTRY
.iter()
.map(|(short, full)| (short.to_string(), full.to_string()).into())
.collect::<Vec<Row>>();
let mut table = Table::new(data);
table::default_style(&mut table, false);
miseprintln!("{table}");
}

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(())
}
}
Expand All @@ -63,6 +56,9 @@ static AFTER_LONG_HELP: &str = color_print::cstr!(
node core:node
poetry asdf:mise-plugins/mise-poetry
ubi cargo:ubi-cli
$ <bold>mise registry poetry</bold>
asdf:mise-plugins/mise-poetry
"#
);

Expand Down
4 changes: 0 additions & 4 deletions src/config/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,6 @@ impl Display for Settings {
}
}

pub fn ensure_experimental(what: &str) -> Result<()> {
Settings::get().ensure_experimental(what)
}

pub const DEFAULT_NODE_MIRROR_URL: &str = "https://nodejs.org/dist/";

impl SettingsNode {
Expand Down

0 comments on commit c52be46

Please sign in to comment.