-
Notifications
You must be signed in to change notification settings - Fork 1
/
help_message.go
53 lines (44 loc) · 979 Bytes
/
help_message.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
package commander
import (
"bytes"
"strings"
)
const _HelpMessageSpace string = " "
type _HelpMessage struct {
buffer bytes.Buffer
}
func (h *_HelpMessage) write(s string, spaces int) (int, error) {
for ; spaces > 0; spaces-- {
s = _HelpMessageSpace + s
}
return h.buffer.WriteString(s)
}
func (h *_HelpMessage) Line() *_HelpMessage {
h.buffer.WriteString("\n")
return h
}
func (h *_HelpMessage) Description(s string) error {
_, err := h.write(s+"\n\n", 1)
return err
}
func (h *_HelpMessage) Title(s string) error {
_, err := h.write(s+":\n", 1)
return err
}
func (h *_HelpMessage) Subtitle(s string) error {
if strings.Contains(s, "\n") {
strs := strings.Split(s, "\n")
for _, str := range strs {
if len(strings.TrimSpace(str)) == 0 {
} else if _, err := h.write(str+"\n", 2); err != nil {
return err
}
}
return nil
}
_, err := h.write(s+"\n", 2)
return err
}
func (h _HelpMessage) String() string {
return h.buffer.String()
}