Add scoped PromptKit flag aliases

This commit is contained in:
2026-11-07 04:27:28 +00:00
parent 644e6c365b
commit 0183022a28
13 changed files with 237 additions and 38 deletions

View File

@@ -63,6 +63,10 @@ type inputAssignment struct {
// Named resource inspections return native reports through shared formatting.
// Catalog commands accept config/overlay selection and suite selectors.
func Command[I, S any](suite Suite[I, S]) commandkit.Command {
return buildCommand(suite, nil)
}
func buildCommand[I, S any](suite Suite[I, S], aliases *[]commandkit.Declaration) commandkit.Command {
if suite.InspectPrompt == nil && suite.InspectProfile == nil && suite.InspectBackend == nil && suite.InspectRequirements == nil && suite.ValidateRequest == nil && suite.PrepareRequest == nil && suite.SmokeTest == nil && suite.ListPrompts == nil && suite.ListProfiles == nil && suite.ListBackends == nil && suite.ListNamespaces == nil && suite.ListCollections == nil {
command := commandkit.NoCommand()
for _, issue := range suite.issues {
@@ -75,16 +79,16 @@ func Command[I, S any](suite Suite[I, S]) commandkit.Command {
rootCommands := make([]commandkit.Command, 0, 3)
showCommands := make([]commandkit.Command, 0, 2)
if suite.InspectPrompt != nil {
showCommands = append(showCommands, newDefinitionCommand(suite, "prompt"))
showCommands = append(showCommands, newDefinitionCommand(suite, "prompt", aliases))
}
if suite.InspectProfile != nil {
showCommands = append(showCommands, newDefinitionCommand(suite, "profile"))
showCommands = append(showCommands, newDefinitionCommand(suite, "profile", aliases))
}
if suite.InspectBackend != nil {
showCommands = append(showCommands, newDefinitionCommand(suite, "backend"))
showCommands = append(showCommands, newDefinitionCommand(suite, "backend", aliases))
}
if suite.PrepareRequest != nil {
showCommands = append(showCommands, newPreparationCommand(suite))
showCommands = append(showCommands, newPreparationCommand(suite, aliases))
}
if len(showCommands) != 0 {
rootCommands = append(rootCommands, commandkit.Group("show", "Show a named PromptKit definition.", showCommands...))
@@ -110,16 +114,16 @@ func Command[I, S any](suite Suite[I, S]) commandkit.Command {
}
requirementsCommands := make([]commandkit.Command, 0, 2)
if suite.InspectRequirements != nil {
requirementsCommands = append(requirementsCommands, newRequirementsCommand(suite))
requirementsCommands = append(requirementsCommands, newRequirementsCommand(suite, aliases))
}
if suite.ValidateRequest != nil {
requirementsCommands = append(requirementsCommands, newValidationCommand(suite))
requirementsCommands = append(requirementsCommands, newValidationCommand(suite, aliases))
}
if len(requirementsCommands) != 0 {
rootCommands = append(rootCommands, commandkit.Group("requirements", "Inspect and validate prompt requirements.", requirementsCommands...))
}
if suite.SmokeTest != nil {
rootCommands = append(rootCommands, newSmokeTestCommand(suite))
rootCommands = append(rootCommands, newSmokeTestCommand(suite, aliases))
}
command := commandkit.RootGroup("promptkit", "Inspect, list, validate requests, and run PromptKit smoke tests.", rootCommands...)
for _, issue := range suite.issues {
@@ -231,7 +235,7 @@ func prepareCatalogInput[I, S any](suite Suite[I, S], input *catalogInput[I]) (I
return prepareSuiteInput(suite, input.selection, input.captured)
}
func newDefinitionCommand[I, S any](suite Suite[I, S], name string) commandkit.Command {
func newDefinitionCommand[I, S any](suite Suite[I, S], name string, aliases *[]commandkit.Declaration) commandkit.Command {
flags := commandkit.CaptureFlags(suite.Selectors, func(input **definitionInput[I]) *commandkit.FlagValues[I] {
if input == nil || *input == nil {
return nil
@@ -247,7 +251,7 @@ func newDefinitionCommand[I, S any](suite Suite[I, S], name string) commandkit.C
}),
)
if suite.namespaces != nil {
flags = append(flags, namespaceFlags(func(input **definitionInput[I]) *namespaceInput { return &(*input).namespaces }, name)...)
flags = appendRequestBindings(flags, "promptkit show "+name, aliases, namespaceFlags(func(input **definitionInput[I]) *namespaceInput { return &(*input).namespaces }, name)...)
}
spec := commandkit.CommandSpec[*definitionInput[I]]{
@@ -276,7 +280,7 @@ func newDefinitionCommand[I, S any](suite Suite[I, S], name string) commandkit.C
return commandkit.NewCommand(spec)
}
func newRequirementsCommand[I, S any](suite Suite[I, S]) commandkit.Command {
func newRequirementsCommand[I, S any](suite Suite[I, S], aliases *[]commandkit.Declaration) commandkit.Command {
flags := commandkit.CaptureFlags(suite.Selectors, func(input **requirementsInput[I]) *commandkit.FlagValues[I] {
if input == nil || *input == nil {
return nil
@@ -296,10 +300,10 @@ func newRequirementsCommand[I, S any](suite Suite[I, S]) commandkit.Command {
resources := NewResourceFlags(func(input **requirementsInput[I]) *ResourceInput { return &(*input).resources })
inputs := NewPromptInputFlags(func(input **requirementsInput[I]) *PromptInputs { return &(*input).inputs })
flags = append(flags, resources.Profile, resources.SessionID, inputs.Variable)
flags = appendRequestBindings(flags, "promptkit requirements show", aliases, requestBinding[*requirementsInput[I]]{resources.Profile, requestFlags.Profile}, requestBinding[*requirementsInput[I]]{resources.SessionID, requestFlags.SessionID}, requestBinding[*requirementsInput[I]]{inputs.Variable, requestFlags.Var})
if suite.namespaces != nil {
flags = append(flags, namespaceFlags(func(input **requirementsInput[I]) *namespaceInput { return &(*input).namespaces }, "prompt", "profile")...)
flags = appendRequestBindings(flags, "promptkit requirements show", aliases, namespaceFlags(func(input **requirementsInput[I]) *namespaceInput { return &(*input).namespaces }, "prompt", "profile")...)
}
spec := commandkit.CommandSpec[*requirementsInput[I]]{