MCPcopy Index your code
hub / github.com/nikivdev/go / runPrompt

Function runPrompt

cli/spec/main.go:120–174  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

118}
119
120func runPrompt(args []string) error {
121 fs := flag.NewFlagSet(commandName, flag.ContinueOnError)
122 fs.SetOutput(os.Stderr)
123
124 inPathFlag := fs.String("in", "", "Path to markdown spec file")
125 printPrompt := fs.Bool("stdout", false, "Also print generated prompt to stdout")
126 noClipboard := fs.Bool("no-clipboard", false, "Do not copy generated prompt to clipboard")
127 mode := fs.String("mode", "codex", "Prompt target mode (currently only: codex)")
128
129 if err := fs.Parse(normalizeArgs(args)); err != nil {
130 if errors.Is(err, flag.ErrHelp) {
131 return nil
132 }
133 return err
134 }
135
136 path := strings.TrimSpace(*inPathFlag)
137 if path == "" {
138 rest := fs.Args()
139 if len(rest) > 0 {
140 path = strings.TrimSpace(rest[0])
141 }
142 }
143 if path == "" {
144 printUsage()
145 return errors.New("missing markdown spec file path")
146 }
147
148 bundle, err := buildPromptBundle(path, *mode)
149 if err != nil {
150 return err
151 }
152
153 copied := false
154 if !*noClipboard {
155 if err := copyToClipboard(bundle.Prompt); err != nil {
156 if !*printPrompt {
157 fmt.Println(bundle.Prompt)
158 }
159 return fmt.Errorf("copy to clipboard failed: %w", err)
160 }
161 copied = true
162 }
163
164 if *printPrompt || *noClipboard {
165 fmt.Print(bundle.Prompt)
166 }
167
168 fmt.Fprintf(os.Stderr, "Generated prompt from %s (%d chars)\n", bundle.SpecPath, len(bundle.Prompt))
169 if copied {
170 fmt.Fprintln(os.Stderr, "Copied prompt to clipboard.")
171 }
172
173 return nil
174}
175
176func runExec(args []string) error {
177 localArgs, codexArgs := splitArgsAtDoubleDash(args)

Callers 1

mainFunction · 0.85

Calls 5

normalizeArgsFunction · 0.85
printUsageFunction · 0.85
buildPromptBundleFunction · 0.85
copyToClipboardFunction · 0.85
StringMethod · 0.80

Tested by

no test coverage detected