formatExamples formats the examples as width wrapped bulletpoint descriptions with the command underneath.
(examples ...example)
| 79 | // formatExamples formats the examples as width wrapped bulletpoint |
| 80 | // descriptions with the command underneath. |
| 81 | func 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 | |
| 103 | var ( |
| 104 | version string |
no outgoing calls
no test coverage detected