MCPcopy Index your code
hub / github.com/coder/coder / wordLiteral

Function wordLiteral

coderd/util/shellparse/shellparse.go:55–79  ·  view source on GitHub ↗

wordLiteral returns the literal content of w by concatenating the literal pieces of its parts. Bare literals, single-quoted strings, and double-quoted strings (when the inner parts are all literals) contribute their text. Any part involving variable expansion, command substitution, or arithmetic ret

(w *syntax.Word)

Source from the content-addressed store, hash-verified

53// command substitution, or arithmetic returns "" for the whole word
54// because we cannot resolve those without executing the shell.
55func wordLiteral(w *syntax.Word) string {
56 if w == nil {
57 return ""
58 }
59 var sb strings.Builder
60 for _, part := range w.Parts {
61 switch p := part.(type) {
62 case *syntax.Lit:
63 _, _ = sb.WriteString(p.Value)
64 case *syntax.SglQuoted:
65 _, _ = sb.WriteString(p.Value)
66 case *syntax.DblQuoted:
67 for _, inner := range p.Parts {
68 lit, ok := inner.(*syntax.Lit)
69 if !ok {
70 return ""
71 }
72 _, _ = sb.WriteString(lit.Value)
73 }
74 default:
75 return ""
76 }
77 }
78 return sb.String()
79}
80
81// cmdBase returns the base name of a command path, handling both
82// forward and back slashes since commands may originate from Windows

Callers 2

ParseFunction · 0.85
firstNonFlagLiteralFunction · 0.85

Calls 2

WriteStringMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected