FormatExamples formats the examples as width wrapped bulletpoint descriptions with the command underneath.
(examples ...Example)
| 1149 | // FormatExamples formats the examples as width wrapped bulletpoint |
| 1150 | // descriptions with the command underneath. |
| 1151 | func 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. |
| 1174 | func (r *RootCmd) Verbosef(inv *serpent.Invocation, fmtStr string, args ...interface{}) { |