-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
114 lines (101 loc) · 2.39 KB
/
helpers.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package util
import (
"os"
"time"
"github.com/urfave/cli"
)
// Command returns a cli.Command
func Command(
name string,
usage string,
action interface{},
subcommands cli.Commands,
flags []cli.Flag,
aliases ...string,
) cli.Command {
return cli.Command{
Name: name,
Aliases: aliases,
Usage: usage,
Action: action,
Subcommands: subcommands,
Flags: flags,
}
}
// SubCommands returns a slice of cli.Command
func SubCommands(sc ...cli.Command) []cli.Command {
return append([]cli.Command{}, sc...)
}
// Lang returns an cli.StringFlag
func Lang(name, usage, value string, dest *string) *cli.StringFlag {
return &cli.StringFlag{
Name: name,
Usage: usage,
Value: value,
Destination: dest,
}
}
// String returns an cli.StringFlag
func String(name, usage, value string, dest *string) *cli.StringFlag {
return &cli.StringFlag{
Name: name,
Usage: usage,
Value: value,
Destination: dest,
}
}
// BoolTrue returns a CliBoolFlag that defaults to true
func BoolTrue(name, usage string, dest *bool) *cli.BoolTFlag {
return &cli.BoolTFlag{
Name: name,
Usage: usage,
Destination: dest,
}
}
// Bool returns an cli.BoolFlag
func Bool(name, usage string, dest *bool) *cli.BoolFlag {
return &cli.BoolFlag{
Name: name,
Usage: usage,
Destination: dest,
}
}
// Join joins together a path and filename
func Join(path, filename string) string {
return path + string(os.PathSeparator) + filename
}
// StringSlice returns and cli.StringSliceFlag
func StringSlice(name, usage string, value *cli.StringSlice) *cli.StringSliceFlag {
return &cli.StringSliceFlag{
Name: name,
Usage: usage,
Value: value,
}
}
// Int returns an cli.IntFlag
func Int(name, usage string, value int, dest *int) *cli.IntFlag {
return &cli.IntFlag{
Name: name,
Value: value,
Usage: usage,
Destination: dest,
}
}
// Duration returns an cli.DurationFlag
func Duration(name, usage string, value time.Duration, dest *time.Duration) *cli.DurationFlag {
return &cli.DurationFlag{
Name: name,
Value: value,
Usage: usage,
Destination: dest,
}
}
// Float64 returns an cli.Float64Flag
func Float64(name, usage string, value float64, dest *float64) *cli.Float64Flag {
return &cli.Float64Flag{
Name: name,
Value: value,
Usage: usage,
Destination: dest,
}
}