/
help.go
61 lines (54 loc) · 1.39 KB
/
help.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
54
55
56
57
58
59
60
61
package tool
import (
"bytes"
"sort"
)
// Help returns text with manual for user.
func Help() string {
list := registeredFormats()
sort.Slice(list, func(i, j int) bool {
if list[i].input == list[j].input {
return list[i].output < list[j].output
}
return list[i].input < list[j].input
})
b := &bytes.Buffer{}
b.WriteString("Usage: ema <input> <output>\n\n")
b.WriteString("Arguments:\n")
b.WriteString(" path/to/file.ext to use file\n")
b.WriteString(" path/to/file.ext#<format> to use file as format\n")
b.WriteString(" -#<format> to use stdin/stdout as format\n")
b.WriteByte('\n')
b.WriteString("Formats:\n")
for _, v := range list {
b.WriteString(" ")
b.WriteString(v.input)
b.WriteString(" -> ")
b.WriteString(v.output)
b.WriteByte('\n')
}
b.WriteByte('\n')
b.WriteString("Examples:\n")
b.WriteString(" ema file.ema file.json\n")
b.WriteString(" ema file.ext#ema file.json\n")
b.WriteString(" ema file.ema -#json\n")
b.WriteString(" ema -#ema -#json\n")
b.WriteByte('\n')
return b.String()
}
type formats struct {
input string
output string
}
func registeredFormats() []formats {
registeredWorkersMutex.Lock()
defer registeredWorkersMutex.Unlock()
list := make([]formats, 0, len(registeredWorkers))
for key := range registeredWorkers {
list = append(list, formats{
input: key[0],
output: key[1],
})
}
return list
}