MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / parseExamples

Function parseExamples

internal/cmdhelp/json.go:483–500  ·  view source on GitHub ↗

parseExamples turns cobra's Example field (a single multiline string) into individual Example entries. Each non-empty, non-comment line is taken as one runnable invocation; comment lines (`# ...`) are dropped. The convention in pad's existing commands is two-space-indented lines like: pad item cr

(example string)

Source from the content-addressed store, hash-verified

481//
482// We trim leading/trailing whitespace per line.
483func parseExamples(example string) []Example {
484 example = strings.TrimSpace(example)
485 if example == "" {
486 return nil
487 }
488 var examples []Example
489 for _, line := range strings.Split(example, "\n") {
490 line = strings.TrimSpace(line)
491 if line == "" || strings.HasPrefix(line, "#") {
492 continue
493 }
494 examples = append(examples, Example{Cmd: line})
495 }
496 if len(examples) == 0 {
497 return nil
498 }
499 return examples
500}
501
502// firstLine returns the first line of s with surrounding whitespace
503// trimmed. Useful for collapsing a multi-line Long string into a Summary.

Callers 2

buildCommandFunction · 0.85

Calls

no outgoing calls