diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/dev/pages/issues/the-shit-time.md | 42 | ||||
| -rw-r--r-- | docs/example-pages/examples.json | 34 |
2 files changed, 74 insertions, 2 deletions
diff --git a/docs/dev/pages/issues/the-shit-time.md b/docs/dev/pages/issues/the-shit-time.md index b23854e..4c25e8f 100644 --- a/docs/dev/pages/issues/the-shit-time.md +++ b/docs/dev/pages/issues/the-shit-time.md @@ -34,7 +34,7 @@ fn complete(ctx: &ShellContext) -> Suggest { // ... } ``` - + Final implementation: By adding support for `EntryFallback` (formerly `ErrorDispatcherNotFound`) to the Completion system, `EntryFallback` can now be used as a completion entry point when no subcommand is matched: @@ -48,7 +48,7 @@ fn complete_fallback(_ctx: &ShellContext) -> Suggest { --- -## Why can't I register descriptions for commands? +## Why can't I register descriptions for commands? (Solved) (completion) (dispatcher) @@ -109,3 +109,41 @@ fn desc_add(_ctx: &ShellContext) -> Suggest { // Match the corresponding function using enum values inside ThisProgram gen_program!() ``` + +Final implementation: + +`#[metadata]` registers a `Description` for each entry, and `gen_program!()` collects them. During completion, when a subcommand suggestion is generated, its owning entry's `Description` is resolved via the node path and attached as the suggestion's description text. + +```rust +use mingling::{ + ShellContext, Suggest, + macros::{command, completion, gen_program, metadata, suggest}, + metadata::Description, + setup::picker::BasicProgramSetup, +}; + +fn main() { + let mut program = ThisProgram::new(); + program.with_setup(BasicProgramSetup); + program.with_dispatcher(CMDCompletion); + program.with_dispatcher(CMDThanks); + program.exec_and_exit(); +} + +#[command] +pub fn thanks() { + println!("thanks!"); +} + +#[completion(EntryThanks)] +pub fn complete_thanks(_ctx: &ShellContext) -> Suggest { + suggest! { "alice", "bob" } +} + +#[metadata(EntryThanks)] +pub fn desc_thanks() -> Description { + Description::new("Thanks someone") +} + +gen_program!(); +``` diff --git a/docs/example-pages/examples.json b/docs/example-pages/examples.json index bde9d35..31336f1 100644 --- a/docs/example-pages/examples.json +++ b/docs/example-pages/examples.json @@ -95,6 +95,24 @@ ] }, { + "id": "example-combine-pathf-metadata", + "name": "Pathfinder + Metadata", + "icon": "🧭", + "category": "advanced", + "desc": "Combines the `pathf` feature with entry metadata. The metadata `DataType` and the entry `BindType` are defined inside a submodule, and `pathf` resolves them for `gen_program!()` at build time.\n", + "tags": [ + "pathf", + "metadata", + "build.rs" + ], + "files": [ + "src/main.rs", + "src/sub/mod.rs", + "build.rs", + "Cargo.toml" + ] + }, + { "id": "example-command-macro", "name": "Command Macro", "icon": "🚀", @@ -254,6 +272,22 @@ ] }, { + "id": "example-metadata", + "name": "Entry Metadata", + "icon": "🏷️", + "category": "advanced", + "desc": "Demonstrates attaching arbitrary, compile-time-typed metadata to an entry via `#[metadata(Entry)]` and retrieving it at runtime with `ProgramCollect::get_metadata`. No `pathf` needed here — everything lives in a single module.\n", + "tags": [ + "metadata", + "get_metadata", + "extras" + ], + "files": [ + "src/main.rs", + "Cargo.toml" + ] + }, + { "id": "example-outside-type", "name": "Outside Type", "icon": "🆕", |
