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

Function FormatExamples

cli/root.go:1151–1171  ·  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

1149// FormatExamples formats the examples as width wrapped bulletpoint
1150// descriptions with the command underneath.
1151func FormatExamples(examples ...Example) string {
1152 var sb strings.Builder
1153
1154 padStyle := cliui.DefaultStyles.Wrap.With(pretty.XPad(4, 0))
1155 for i, e := range examples {
1156 if len(e.Description) > 0 {
1157 wordwrap.WrapString(e.Description, 80)
1158 _, _ = sb.WriteString(
1159 " - " + pretty.Sprint(padStyle, e.Description+":")[4:] + "\n\n ",
1160 )
1161 }
1162 // We add 1 space here because `cliui.DefaultStyles.Code` adds an extra
1163 // space. This makes the code block align at an even 2 or 6
1164 // spaces for symmetry.
1165 _, _ = sb.WriteString(" " + pretty.Sprint(cliui.DefaultStyles.Code, fmt.Sprintf("$ %s", e.Command)))
1166 if i < len(examples)-1 {
1167 _, _ = sb.WriteString("\n\n")
1168 }
1169 }
1170 return sb.String()
1171}
1172
1173// Verbosef logs a message if verbose mode is enabled.
1174func (r *RootCmd) Verbosef(inv *serpent.Invocation, fmtStr string, args ...interface{}) {

Callers 15

prebuildsMethod · 0.92
templatePresetsMethod · 0.85
externalAuthAccessTokenFunction · 0.85
templatesMethod · 0.85
portForwardMethod · 0.85
taskSendMethod · 0.85
taskPauseMethod · 0.85
Test_formatExamplesFunction · 0.85
scheduleStartMethod · 0.85

Calls 2

WriteStringMethod · 0.80
StringMethod · 0.45

Tested by 1

Test_formatExamplesFunction · 0.68