MCPcopy Create free account
hub / github.com/cli/cli / dedent

Function dedent

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

Source from the content-addressed store, hash-verified

302}
303
304func dedent(s string) string {
305 lines := strings.Split(s, "\n")
306 minIndent := -1
307
308 for _, l := range lines {
309 if len(l) == 0 {
310 continue
311 }
312
313 indent := len(l) - len(strings.TrimLeft(l, " "))
314 if minIndent == -1 || indent < minIndent {
315 minIndent = indent
316 }
317 }
318
319 if minIndent <= 0 {
320 return s
321 }
322
323 var buf bytes.Buffer
324 for _, l := range lines {
325 fmt.Fprintln(&buf, strings.TrimPrefix(l, strings.Repeat(" ", minIndent)))
326 }
327 return strings.TrimSuffix(buf.String(), "\n")
328}
329
330func BuildAliasList(cmd *cobra.Command, aliases []string) []string {
331 if !cmd.HasParent() {

Callers 5

rootUsageFuncFunction · 0.85
WriteHelpFunction · 0.85
longPagerFunction · 0.85
cmdRefFunction · 0.85
TestDedentFunction · 0.85

Calls 1

StringMethod · 0.65

Tested by 1

TestDedentFunction · 0.68