Skip to content

Commit

Permalink
feat(registry): map ubi -> cargo:ubi (#2110)
Browse files Browse the repository at this point in the history
* feat(tasks): add --json flag (#2116)

* tasks: add --json flag

Fixes #2043

* Render help

* feat: map ubi -> cargo:ubi

* Commit from GitHub Actions (test)

---------

Co-authored-by: Lev Vereshchagin <[email protected]>
Co-authored-by: mise[bot] <[email protected]>
  • Loading branch information
3 people authored May 15, 2024
1 parent d327027 commit e3080ba
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,9 @@ Options:
[possible values: asc, desc]
-J, --json
Output in JSON format
Examples:
$ mise tasks ls
Expand Down
19 changes: 19 additions & 0 deletions src/cli/args/forge_arg.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use std::collections::HashMap;
use std::fmt::{Debug, Display};
use std::hash::Hash;
use std::path::PathBuf;

use once_cell::sync::Lazy;

use crate::dirs;
use crate::forge::{unalias_forge, ForgeType};
use crate::registry::REGISTRY;

#[derive(Clone, PartialOrd, Ord)]
pub struct ForgeArg {
Expand All @@ -17,6 +21,9 @@ pub struct ForgeArg {

impl From<&str> for ForgeArg {
fn from(s: &str) -> Self {
if let Some(fa) = FORGE_MAP.get(s) {
return fa.clone();
}
if let Some((forge_type, name)) = s.split_once(':') {
if let Ok(forge_type) = forge_type.parse() {
return Self::new(forge_type, name);
Expand Down Expand Up @@ -76,6 +83,18 @@ impl Hash for ForgeArg {
}
}

static FORGE_MAP: Lazy<HashMap<&'static str, ForgeArg>> = Lazy::new(|| {
REGISTRY
.iter()
.map(|(short, full)| {
let (forge_type, name) = full.split_once(':').unwrap();
let forge_type = forge_type.parse().unwrap();
let fa = ForgeArg::new(forge_type, name);
(*short, fa)
})
.collect()
});

#[cfg(test)]
mod tests {
use super::*;
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ mod migrate;
mod path_env;
mod plugins;
mod rand;
mod registry;
mod runtime_symlinks;
mod shell;
mod shims;
Expand Down
4 changes: 4 additions & 0 deletions src/registry.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub const REGISTRY: &[(&str, &str)] = &[
("ubi", "cargo:ubi"),
// ("elixir", "asdf:mise-plugins/mise-elixir"),
];

0 comments on commit e3080ba

Please sign in to comment.