-
Notifications
You must be signed in to change notification settings - Fork 86
/
help.go
70 lines (51 loc) · 1.24 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
62
63
64
65
66
67
68
69
70
package worker
import (
"fmt"
"io"
"sort"
"github.com/travis-ci/worker/backend"
"gopkg.in/urfave/cli.v1"
)
var (
cliHelpPrinter = cli.HelpPrinter
)
const (
providerHelpHeader = `
All provider options must be given as environment variables of the form:
$[TRAVIS_WORKER_]{UPCASE_PROVIDER_NAME}_{UPCASE_UNDERSCORED_KEY}
^------------^
optional namespace
e.g.:
TRAVIS_WORKER_DOCKER_HOST='tcp://127.0.0.1:4243'
TRAVIS_WORKER_DOCKER_PRIVILEGED='true'
`
)
func init() {
cli.HelpPrinter = helpPrinter
}
func helpPrinter(w io.Writer, templ string, data interface{}) {
cliHelpPrinter(w, templ, data)
fmt.Fprint(w, providerHelpHeader)
margin := 4
maxLen := 0
backend.EachBackend(func(b *backend.Backend) {
for itemKey := range b.ProviderHelp {
if len(itemKey) > maxLen {
maxLen = len(itemKey)
}
}
})
itemFmt := fmt.Sprintf("%%%ds - %%s\n", maxLen+margin)
backend.EachBackend(func(b *backend.Backend) {
fmt.Fprintf(w, "\n%s provider help:\n\n", b.HumanReadableName)
sortedKeys := []string{}
for key := range b.ProviderHelp {
sortedKeys = append(sortedKeys, key)
}
sort.Strings(sortedKeys)
for _, key := range sortedKeys {
fmt.Printf(itemFmt, key, b.ProviderHelp[key])
}
})
fmt.Println("")
}