MCPcopy Index your code
hub / github.com/larksuite/cli / stripCmdSubst

Function stripCmdSubst

cmd/cmdexample_parse_test.go:167–188  ·  view source on GitHub ↗

stripCmdSubst removes $(...) command substitutions (including nested ones) from s, leaving the surrounding text intact. Backtick substitutions are already handled upstream (a command never spans a backtick).

(s string)

Source from the content-addressed store, hash-verified

165// from s, leaving the surrounding text intact. Backtick substitutions are
166// already handled upstream (a command never spans a backtick).
167func stripCmdSubst(s string) string {
168 var b strings.Builder
169 depth := 0
170 for i := 0; i < len(s); i++ {
171 if depth == 0 && i+1 < len(s) && s[i] == '$' && s[i+1] == '(' {
172 depth = 1
173 i++ // skip '('
174 continue
175 }
176 if depth > 0 {
177 switch s[i] {
178 case '(':
179 depth++
180 case ')':
181 depth--
182 }
183 continue
184 }
185 b.WriteByte(s[i])
186 }
187 return b.String()
188}
189
190// isPlaceholderOrProse reports whether a command word is a doc placeholder
191// (<resource>, [flags], {a|b}, +<verb>, ...) or narration (CJK / other

Callers 1

parseCmdFunction · 0.85

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected