-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli_flow.go
More file actions
99 lines (91 loc) · 2.46 KB
/
Copy pathcli_flow.go
File metadata and controls
99 lines (91 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"flag"
"strings"
"github.com/dotcommander/prompter/internal/config"
)
const (
commandApply = "apply"
commandBrowse = "browse"
commandConfigAlias = "config"
commandConfigure = "configure"
commandCritique = "critique"
commandImage = "image"
commandModels = "models"
commandPrompts = "prompts"
commandRefine = "refine"
commandRewrite = "rewrite"
)
// interspersedFlagArgs moves recognized flag tokens before positional input so
// flag.FlagSet can accept documented forms such as "subject --count 3". Tokens
// after -- remain literal positional input.
func interspersedFlagArgs(fs *flag.FlagSet, args []string) []string {
flags := make([]string, 0, len(args))
positional := make([]string, 0, len(args))
literal := false
for i := 0; i < len(args); i++ {
arg := args[i]
if literal {
positional = append(positional, arg)
continue
}
if arg == "--" {
literal = true
continue
}
if arg == "-" || !strings.HasPrefix(arg, "-") {
positional = append(positional, arg)
continue
}
flags = append(flags, arg)
name, _, hasInlineValue := strings.Cut(strings.TrimLeft(arg, "-"), "=")
takesValue := false
if registered := fs.Lookup(name); registered != nil {
boolFlag, isBool := registered.Value.(interface{ IsBoolFlag() bool })
takesValue = !isBool || !boolFlag.IsBoolFlag()
}
if takesValue && !hasInlineValue {
if i+1 >= len(args) {
return flags
}
i++
flags = append(flags, args[i])
}
}
if len(positional) == 0 {
return flags
}
return append(append(flags, "--"), positional...)
}
func resolveCommandSystemPrompt(f *flags, cfg *config.Config) error {
switch {
case f.command == commandImage || f.command == commandBrowse || f.command == commandConfigure || f.command == commandModels || f.command == commandPrompts:
return nil
case f.command == commandApply:
validation, err := loadCatalogSystemPrompt(cfg, f.promptName)
if err != nil {
return err
}
f.outputValidation = validation
return nil
case f.command == commandCritique:
cfg.SystemPrompt = defaultCritiquePrompt
return nil
case f.command == commandRewrite:
prompt, err := resolveRewritePrompt(f.rewriteMode)
if err != nil {
return err
}
cfg.SystemPrompt = prompt
return nil
case f.command == commandRefine && f.styleSet:
prompt, err := resolveStyle(f.style)
if err != nil {
return err
}
cfg.SystemPrompt = prompt
return nil
default:
return loadSystemPrompt(cfg)
}
}