MCPcopy Create free account
hub / github.com/github/gh-aw / extractSafeOutputKeys

Function extractSafeOutputKeys

pkg/cli/commands_new_test.go:18–46  ·  view source on GitHub ↗

extractSafeOutputKeys parses a YAML snippet that begins with "safe-outputs:" and returns the list of safe-output type keys that appear at exactly 2 spaces of indentation. Lines indented more deeply are sub-keys of the active entry and are skipped; comment-only lines and the section header itself are

(section string)

Source from the content-addressed store, hash-verified

16// indentation. Lines indented more deeply are sub-keys of the active entry and are
17// skipped; comment-only lines and the section header itself are also skipped.
18func extractSafeOutputKeys(section string) []string {
19 var keys []string
20 for line := range strings.SplitSeq(section, "\n") {
21 // Only examine lines with exactly 2 leading spaces (type-key level).
22 // Sub-keys (e.g. " max: 5") have 4+ spaces and are skipped.
23 if !strings.HasPrefix(line, " ") || strings.HasPrefix(line, " ") {
24 continue
25 }
26 trimmed := strings.TrimSpace(line)
27 if trimmed == "" {
28 continue
29 }
30
31 // Strip a leading comment marker so both active and commented keys are checked.
32 candidate := strings.TrimPrefix(trimmed, "# ")
33
34 // Extract the key name (the part before the colon).
35 key, _, found := strings.Cut(candidate, ":")
36 if !found {
37 continue
38 }
39 key = strings.TrimSpace(key)
40 if key == "" {
41 continue
42 }
43 keys = append(keys, key)
44 }
45 return keys
46}
47
48// TestBuildSafeOutputsSection validates that buildSafeOutputsSection generates
49// safe-output names that are all valid according to the JSON schema.

Calls

no outgoing calls

Tested by

no test coverage detected