MCPcopy Create free account
hub / github.com/coder/wush / formatExamples

Function formatExamples

cmd/wush/main.go:81–101  ·  view source on GitHub ↗

formatExamples formats the examples as width wrapped bulletpoint descriptions with the command underneath.

(examples ...example)

Source from the content-addressed store, hash-verified

79// formatExamples formats the examples as width wrapped bulletpoint
80// descriptions with the command underneath.
81func formatExamples(examples ...example) string {
82 var sb strings.Builder
83
84 padStyle := cliui.DefaultStyles.Wrap.With(pretty.XPad(4, 0))
85 for i, e := range examples {
86 if len(e.Description) > 0 {
87 wordwrap.WrapString(e.Description, 80)
88 _, _ = sb.WriteString(
89 " - " + pretty.Sprint(padStyle, e.Description+":")[4:] + "\n\n ",
90 )
91 }
92 // We add 1 space here because `cliui.DefaultStyles.Code` adds an extra
93 // space. This makes the code block align at an even 2 or 6
94 // spaces for symmetry.
95 _, _ = sb.WriteString(" " + pretty.Sprint(cliui.DefaultStyles.Code, fmt.Sprintf("$ %s", e.Command)))
96 if i < len(examples)-1 {
97 _, _ = sb.WriteString("\n\n")
98 }
99 }
100 return sb.String()
101}
102
103var (
104 version string

Callers 4

cpCmdFunction · 0.85
portForwardCmdFunction · 0.85
rsyncCmdFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected