-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.go
More file actions
56 lines (46 loc) · 1.31 KB
/
cli.go
File metadata and controls
56 lines (46 loc) · 1.31 KB
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
// Wraps urfave/cli and provides some ease of use functions allowing method chaining pattern
package cli
import (
"fmt"
"log"
"time"
"github.com/urfave/cli/v2"
)
func init() {
cli.VersionPrinter = func(c *cli.Context) {
fmt.Fprintf(c.App.Writer, "%s\n", c.App.Version)
}
log.SetFlags(0)
log.SetOutput(&logWriter{})
}
type logWriter struct {
}
func (writer logWriter) Write(bytes []byte) (int, error) {
return fmt.Print(time.Now().UTC().Format("2006-01-02 15:04:05") + ": " + string(bytes))
}
type Args []string
type Callback func(app *Runner, args Args, flags Flags) error
// BooleanFlag specifices a boolean flag variable input by provided name, usage and aliases
func BooleanFlag(name string, usage string, aliases ...string) cli.Flag {
return &cli.BoolFlag{
Name: name,
Usage: usage,
Aliases: aliases,
}
}
// IntegerFlag specifices a integer flag variable input by provided name, usage and aliases
func IntegerFlag(name string, usage string, aliases ...string) cli.Flag {
return &cli.IntFlag{
Name: name,
Usage: usage,
Aliases: aliases,
}
}
// StringFlag specifices a integer flag variable input by provided name, usage and aliases
func StringFlag(name string, usage string, aliases ...string) cli.Flag {
return &cli.StringFlag{
Name: name,
Usage: usage,
Aliases: aliases,
}
}