Document application-owned alias contracts
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
# Consumer guide
|
||||
|
||||
CommandKit is distributed as three Go modules. Start with the core and add an
|
||||
integration module only when the application uses that library. Each module
|
||||
returns core `commandkit.Command` declarations, which the application installs
|
||||
through `commandkit.New` or `App.Register`.
|
||||
integration module only when the application uses that library. Core and
|
||||
integration command factories return canonical `commandkit.Command` values.
|
||||
Applications may install those alongside application-owned `RoutingRule`
|
||||
declarations through `commandkit.New` or `App.Register`; routing rules are
|
||||
installed at the application root, not as group children.
|
||||
|
||||
## Module selection
|
||||
|
||||
@@ -83,6 +85,45 @@ 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.
|
||||
|
||||
## Application-owned aliases
|
||||
|
||||
Pass commands and aliases together as declarations. Integration factories can
|
||||
be called directly in the installation list, and command-scoped flag aliases
|
||||
name the canonical command path:
|
||||
|
||||
```go
|
||||
app, err := commandkit.New(
|
||||
identity,
|
||||
ckprompt.Command(suite),
|
||||
commandkit.Alias("pk", "promptkit"),
|
||||
commandkit.FlagAliasFor("promptkit show prompt", "--fmt", "--format"),
|
||||
)
|
||||
```
|
||||
|
||||
For a reusable collection, use `[]commandkit.Declaration`. Go does not expand a
|
||||
`[]commandkit.Command` into `...commandkit.Declaration`, so convert command-only
|
||||
slices when composing them with routing rules:
|
||||
|
||||
```go
|
||||
commands := []commandkit.Command{ckprompt.Command(suite)}
|
||||
declarations := make([]commandkit.Declaration, 0, len(commands)+1)
|
||||
for _, command := range commands {
|
||||
declarations = append(declarations, command)
|
||||
}
|
||||
declarations = append(declarations, commandkit.Alias("pk", "promptkit"))
|
||||
app, err := commandkit.New(identity, declarations...)
|
||||
```
|
||||
|
||||
New and Register validate each supplied batch before publishing its commands
|
||||
and routing rules. Factories capture their inputs eagerly; malformed or
|
||||
conflicting rules are reported at installation. Identical rules are safe to
|
||||
contribute from reusable helpers. The [core example](../../examples/core) and
|
||||
[composed consumer](../../integrations/ckprompt/examples/composed) show complete
|
||||
maintained wiring with ordinary command behavior alongside aliases. The
|
||||
[application-owned aliases roadmap](../roadmap/aliases.md) records the routing
|
||||
contract; the [CLI reference](../cli.md#application-owned-aliases) describes
|
||||
operator-visible behavior.
|
||||
|
||||
## ConfigKit scopes
|
||||
|
||||
For an application with one ordinary app configuration loader,
|
||||
|
||||
Reference in New Issue
Block a user