-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathexamples.go
More file actions
40 lines (35 loc) · 766 Bytes
/
examples.go
File metadata and controls
40 lines (35 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package examples
import "fmt"
type Example struct {
Description string
Commands []string
}
// Creates a new example
func NewExample(description string, commands ...string) Example {
return Example{
Description: description,
Commands: commands,
}
}
// Returns the example formatted
func (e *Example) format() string {
formatted := fmt.Sprintf(" %s\n", e.Description)
for i, c := range e.Commands {
formatted += fmt.Sprintf(" %s", c)
if i != len(e.Commands)-1 {
formatted += "\n"
}
}
return formatted
}
// Builds a list of formatted examples
func Build(examples ...Example) string {
formatted := ""
for i, e := range examples {
formatted += e.format()
if i != len(examples)-1 {
formatted += "\n\n"
}
}
return formatted
}