MCPcopy
hub / github.com/cli/cli / dedent

Function dedent

pkg/cmd/root/help.go:289–313  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

287}
288
289func dedent(s string) string {
290 lines := strings.Split(s, "\n")
291 minIndent := -1
292
293 for _, l := range lines {
294 if len(l) == 0 {
295 continue
296 }
297
298 indent := len(l) - len(strings.TrimLeft(l, " "))
299 if minIndent == -1 || indent < minIndent {
300 minIndent = indent
301 }
302 }
303
304 if minIndent <= 0 {
305 return s
306 }
307
308 var buf bytes.Buffer
309 for _, l := range lines {
310 fmt.Fprintln(&buf, strings.TrimPrefix(l, strings.Repeat(" ", minIndent)))
311 }
312 return strings.TrimSuffix(buf.String(), "\n")
313}
314
315func BuildAliasList(cmd *cobra.Command, aliases []string) []string {
316 if !cmd.HasParent() {

Callers 5

rootUsageFuncFunction · 0.85
rootHelpFuncFunction · 0.85
longPagerFunction · 0.85
cmdRefFunction · 0.85
TestDedentFunction · 0.85

Calls 1

StringMethod · 0.45

Tested by 1

TestDedentFunction · 0.68