Add strict custom field registry
This commit is contained in:
@@ -9,6 +9,7 @@ $script:GspSubcommands = @(
|
||||
'completion',
|
||||
'validate',
|
||||
'index',
|
||||
'fields',
|
||||
'trace',
|
||||
'flatten',
|
||||
'pack',
|
||||
@@ -27,6 +28,7 @@ $script:GspFlags = @{
|
||||
'completion' = @('powershell', 'bash', 'zsh', 'fish', 'install')
|
||||
'validate' = @('--root', '--out')
|
||||
'index' = @('--root', '--out')
|
||||
'fields' = @('list', 'validate')
|
||||
'trace' = @('--root', '--depth', '--out')
|
||||
'flatten' = @('--root', '--depth', '--include-type', '--exclude-type', '--out')
|
||||
'pack' = @('--root', '--for', '--stage', '--depth', '--budget', '--format', '--include-type', '--exclude-type', '--out')
|
||||
@@ -129,6 +131,12 @@ Register-ArgumentCompleter -Native -CommandName gsp -ScriptBlock {
|
||||
ForEach-Object { New-GspCompletion $_ }
|
||||
}
|
||||
|
||||
if ($command -eq 'fields') {
|
||||
return @($script:GspFlags[$command]) |
|
||||
Where-Object { $_ -like "$wordToComplete*" } |
|
||||
ForEach-Object { New-GspCompletion $_ }
|
||||
}
|
||||
|
||||
if (@('trace', 'flatten', 'pack', 'links', 'impact', 'graph') -contains $command) {
|
||||
return Get-GspIds |
|
||||
Where-Object { $_ -like "$wordToComplete*" } |
|
||||
@@ -148,7 +156,7 @@ _gsp_completion() {
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
cmd="${COMP_WORDS[1]}"
|
||||
local commands="init ai-init version completion validate index trace flatten pack links impact message graph stage-check help"
|
||||
local commands="init ai-init version completion validate index fields trace flatten pack links impact message graph stage-check help"
|
||||
case "$prev" in
|
||||
--format)
|
||||
if [[ "$cmd" == "graph" ]]; then
|
||||
@@ -174,6 +182,7 @@ _gsp_completion() {
|
||||
ai-init) COMPREPLY=( $(compgen -W "--root --agents --skill --all --force" -- "$cur") ) ;;
|
||||
version) COMPREPLY=( $(compgen -W "--json" -- "$cur") ) ;;
|
||||
validate|index) COMPREPLY=( $(compgen -W "--root --out" -- "$cur") ) ;;
|
||||
fields) COMPREPLY=( $(compgen -W "list validate" -- "$cur") ) ;;
|
||||
trace) COMPREPLY=( $(compgen -W "--root --depth --out" -- "$cur") ) ;;
|
||||
flatten) COMPREPLY=( $(compgen -W "--root --depth --include-type --exclude-type --out" -- "$cur") ) ;;
|
||||
pack) COMPREPLY=( $(compgen -W "--root --for --stage --depth --budget --format --include-type --exclude-type --out" -- "$cur") ) ;;
|
||||
@@ -210,6 +219,7 @@ _gsp() {
|
||||
'completion'
|
||||
'validate'
|
||||
'index'
|
||||
'fields'
|
||||
'trace'
|
||||
'flatten'
|
||||
'pack'
|
||||
@@ -228,7 +238,8 @@ _gsp "$@"
|
||||
|
||||
func fishCompletionScript() string {
|
||||
return `# GSP fish completion
|
||||
complete -c gsp -f -n '__fish_use_subcommand' -a 'init ai-init version completion validate index trace flatten pack links impact message graph stage-check help'
|
||||
complete -c gsp -f -n '__fish_use_subcommand' -a 'init ai-init version completion validate index fields trace flatten pack links impact message graph stage-check help'
|
||||
complete -c gsp -n '__fish_seen_subcommand_from fields' -a 'list validate'
|
||||
complete -c gsp -n '__fish_seen_subcommand_from graph' -l format -a 'json mermaid md canvas'
|
||||
complete -c gsp -n '__fish_seen_subcommand_from pack impact' -l format -a 'json md canvas'
|
||||
complete -c gsp -n '__fish_seen_subcommand_from links' -l format -a 'json md'
|
||||
|
||||
@@ -42,6 +42,8 @@ func run(args []string) error {
|
||||
return runValidate(args[1:])
|
||||
case "index":
|
||||
return runIndex(args[1:])
|
||||
case "fields":
|
||||
return runFields(args[1:])
|
||||
case "trace":
|
||||
return runTrace(args[1:])
|
||||
case "flatten":
|
||||
@@ -77,6 +79,7 @@ Usage:
|
||||
gsp completion install powershell
|
||||
gsp validate [--root .] [--out report.json]
|
||||
gsp index [--root .] [--out index.json]
|
||||
gsp fields list|validate [--root .] [--out fields.json]
|
||||
gsp trace <id> [--root .] [--depth 3] [--out trace.json]
|
||||
gsp flatten <id> [--root .] [--depth 3] [--include-type a,b] [--exclude-type a,b] [--out flattened.json]
|
||||
gsp pack <id> [--root .] [--for implement] [--stage implement] [--depth 3] [--budget 12000] [--format json|md|canvas] [--out context-pack.json]
|
||||
@@ -88,6 +91,53 @@ Usage:
|
||||
`)
|
||||
}
|
||||
|
||||
func runFields(args []string) error {
|
||||
if len(args) == 0 {
|
||||
return fmt.Errorf("fields requires list or validate")
|
||||
}
|
||||
switch args[0] {
|
||||
case "list":
|
||||
return runFieldsList(args[1:])
|
||||
case "validate":
|
||||
return runFieldsValidate(args[1:])
|
||||
default:
|
||||
return fmt.Errorf("unknown fields command %q", args[0])
|
||||
}
|
||||
}
|
||||
|
||||
func runFieldsList(args []string) error {
|
||||
fs := flag.NewFlagSet("fields list", flag.ContinueOnError)
|
||||
root := commonRoot(fs)
|
||||
out := commonOut(fs)
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return err
|
||||
}
|
||||
project, err := gsp.LoadProject(*root)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if project.Fields == nil {
|
||||
return writeJSON(*out, map[string]any{"gspFieldsVersion": gsp.FieldsVersion, "fields": map[string]any{}})
|
||||
}
|
||||
return writeJSON(*out, project.Fields)
|
||||
}
|
||||
|
||||
func runFieldsValidate(args []string) error {
|
||||
fs := flag.NewFlagSet("fields validate", flag.ContinueOnError)
|
||||
root := commonRoot(fs)
|
||||
out := commonOut(fs)
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return err
|
||||
}
|
||||
project, err := gsp.LoadProject(*root)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
report := gsp.Report{OK: true}
|
||||
project.ValidateFieldRegistryOnly(&report)
|
||||
return writeReport(*out, report)
|
||||
}
|
||||
|
||||
func runLinks(args []string) error {
|
||||
fs := flag.NewFlagSet("links", flag.ContinueOnError)
|
||||
root := commonRoot(fs)
|
||||
|
||||
Reference in New Issue
Block a user