feat: render toolchain recipes richly via facet-pretty
commit
a999ac0feat: render toolchain recipes richly via facet-pretty
registry::RECIPES becomes &[RecipeInfo] (a #[derive(Facet)]
struct with name/spec/summary) instead of &[&str], so git ents
toolchain recipes renders each recipe as a colored, doc-commented
struct via facet_pretty rather than printing a bare name.
feat: add registry::RecipeInfo Facet struct describing a recipe
feat: render toolchain recipes output via FacetPretty with doc comments enabled
Assisted-by: Claude:claude-sonnet-5
Reviews
No reviews of this commit yet — record a verdict below.
Start a review
crates/git-ents/src/main.rs
@@ -627,8 +627,9 @@
/// Print every recipe `git ents toolchain import --from` accepts.
fn toolchain_recipes() -> Result<(), String> {
+ let printer = facet_pretty::PrettyPrinter::new().with_doc_comments(true);
for recipe in registry::RECIPES {
- println!("{recipe}");
+ println!("{}", recipe.pretty_with(printer.clone()));
}
Ok(())
}
crates/git-ents/src/registry.rs
@@ -12,6 +12,7 @@
use std::path::{Path, PathBuf};
use std::process::Command;
+use facet::Facet;
use git_toolchain::Component;
use tempfile::TempDir;
@@ -40,11 +41,31 @@
_staging: Option<TempDir>,
}
+/// A recipe `git ents toolchain import --from` accepts, described richly
+/// enough to render on its own via `facet_pretty` (see `git ents toolchain
+/// recipes`) rather than as a bare name.
+#[derive(Facet)]
+pub struct RecipeInfo {
+ /// The name passed to `--from`.
+ pub name: &'static str,
+ /// What `--from-spec` selects for this recipe, e.g. a rustup channel or
+ /// version name.
+ pub spec: &'static str,
+ /// What this recipe does, in one line.
+ pub summary: &'static str,
+}
+
/// Every recipe `resolve` knows, for `git ents toolchain recipes` and
/// `resolve`'s own error message — a plain list rather than a trait registry,
/// since each recipe is one function with its own selector semantics, not a
/// uniform interface worth abstracting over for a list of one.
-pub const RECIPES: &[&str] = &["rustup"];
+pub const RECIPES: &[RecipeInfo] = &[RecipeInfo {
+ name: "rustup",
+ spec: "a channel or version, e.g. stable, nightly, 1.75.0",
+ summary: "Resolves a rustup-managed toolchain via `rustc +<spec> -vV`; \
+ by default points at rust-lang's own hosted, hash-pinned \
+ component archives instead of importing local bytes.",
+}];
/// Resolve `recipe` against `spec` (a recipe-specific selector, e.g. a
/// rustup toolchain name). See [`RECIPES`] for what's known.
@@ -58,7 +79,11 @@
"rustup" => rustup(spec, embed),
other => Err(format!(
"unknown toolchain recipe {other:?} (known: {})",
- RECIPES.join(", ")
+ RECIPES
+ .iter()
+ .map(|recipe| recipe.name)
+ .collect::<Vec<_>>()
+ .join(", ")
)),
}
}