use anyhow::Result;
use super::{GeneratedFile, Mechanism, MechanismContext, StepResult};
pub struct Mise;
impl Mechanism for Mise {
fn id(&self) -> &'static str {
"mise"
}
fn description(&self) -> &'static str {
"docs snippet: mise github backend + tool_alias"
}
fn generate(&self, ctx: &MechanismContext<'_>) -> Result<StepResult> {
let p = &ctx.config.project;
let bin = &p.binary_name;
let slug = ctx.config.github_slug();
let version = &p.version;
let md = format!(
r#"# mise
`{bin}` is not in the built-in mise registry. Use the GitHub backend:
```bash
mise use -g github:{slug}@{version}
```
Or in `mise.toml`:
```toml
[tools]
"github:{slug}" = "{version}"
```
To keep a short name in `.tool-versions` (`{bin} {version}`):
```toml
[tool_alias]
{bin} = "github:{slug}"
```
If multiple assets match, narrow with `matching = "{bin}-"`.
"#
);
let base = format!(
"{}/mise",
ctx.config.paths.packaging_dir.trim_end_matches('/')
);
Ok(StepResult {
files: vec![GeneratedFile {
relative_path: format!("{base}/README.md"),
contents: md,
executable: false,
}],
notes: vec![format!("Users: mise use -g github:{slug}@{version}")],
})
}
}