Add scoped PromptKit flag aliases
This commit is contained in:
31
integrations/ckprompt/declarations.go
Normal file
31
integrations/ckprompt/declarations.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package ckprompt
|
||||
|
||||
import commandkit "go.maximumdirect.net/commandkit"
|
||||
|
||||
type requestBinding[I any] struct {
|
||||
flag commandkit.Flag[I]
|
||||
definition requestFlagDefinition
|
||||
}
|
||||
|
||||
// appendRequestBindings installs the selected handles and, when requested,
|
||||
// records their convenience aliases for the exact owning command.
|
||||
func appendRequestBindings[I any](flags []commandkit.Flag[I], path string, aliases *[]commandkit.Declaration, bindings ...requestBinding[I]) []commandkit.Flag[I] {
|
||||
for _, binding := range bindings {
|
||||
flags = append(flags, binding.flag)
|
||||
if aliases != nil {
|
||||
for _, name := range binding.definition.aliases {
|
||||
*aliases = append(*aliases, commandkit.FlagAliasFor(path, "--"+name, "--"+binding.definition.meta.Name))
|
||||
}
|
||||
}
|
||||
}
|
||||
return flags
|
||||
}
|
||||
|
||||
// Declarations returns the canonical PromptKit command family and scoped
|
||||
// convenience aliases for the operations and flags enabled by suite. Command
|
||||
// remains available for installations that want only canonical spellings.
|
||||
func Declarations[I, S any](suite Suite[I, S]) []commandkit.Declaration {
|
||||
var aliases []commandkit.Declaration
|
||||
command := buildCommand(suite, &aliases)
|
||||
return append([]commandkit.Declaration{command}, aliases...)
|
||||
}
|
||||
Reference in New Issue
Block a user