Add completion hints to maintained commands
This commit is contained in:
@@ -87,6 +87,34 @@ values convert before input construction. A command's `NewInput` creates input
|
||||
only when execution reaches it; help does not construct caller input or run
|
||||
provider callbacks.
|
||||
|
||||
## Shell completion
|
||||
|
||||
Install `commandkit.Completion("app")` alongside the application's other
|
||||
declarations, using the basename operators actually type. The basename accepts
|
||||
letters, digits, underscores, dots, hyphens, and colons, except for a leading
|
||||
hyphen. Add a hint to a flag or operand's metadata when a value has useful
|
||||
static choices or is a filesystem path:
|
||||
|
||||
```go
|
||||
commandkit.FlagMeta{
|
||||
Name: "format",
|
||||
Completion: commandkit.CompleteChoices(
|
||||
commandkit.CompletionChoice{Value: "text", Description: "Readable text"},
|
||||
commandkit.CompletionChoice{Value: "yaml", Description: "YAML output"},
|
||||
),
|
||||
}
|
||||
commandkit.FlagMeta{Name: "config", Completion: commandkit.CompleteFiles()}
|
||||
commandkit.ArgumentMeta{Name: "directory", Completion: commandkit.CompleteDirectories()}
|
||||
```
|
||||
|
||||
Hints are suggestions: converters and input validation still decide which
|
||||
values are accepted. An omitted hint or `NoCompletion()` gives no value
|
||||
suggestions. `CompleteChoices()` with no choices also gives no suggestions.
|
||||
Declarations retain copies of supplied choices. The [CLI reference](../cli.md#shell-completion)
|
||||
describes supported shells and loading scripts; the [core example](../../examples/core)
|
||||
and [composed example](../../integrations/ckprompt/examples/composed) show
|
||||
installation alongside aliases and integration commands.
|
||||
|
||||
## Invocation reporting
|
||||
|
||||
`Invocation.Reporter()` supplies the reporter for the current handler. Use
|
||||
|
||||
Reference in New Issue
Block a user