-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
50 lines (45 loc) · 1002 Bytes
/
main.go
File metadata and controls
50 lines (45 loc) · 1002 Bytes
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
package main
import (
"fmt"
"github.com/urfave/cli"
"time"
)
func main() {
app := cli.NewApp()
app.Name = "heartbeat"
app.Usage = "Produce a periodic heartbeat message"
app.Version = "0.1.0"
app.Flags = []cli.Flag{
cli.BoolTFlag{
Name: "verbose",
Usage: "Print verbose output",
},
}
app.Commands = []cli.Command{
{
Name: "version",
Aliases: []string{"v"},
Usage: "Print the version and exit",
Action: func(c *cli.Context) error {
fmt.Printf("heartbeat version %s\n", app.Version)
return nil
},
},
{
Name: "run",
Usage: "Run the program",
Action: RunPeriodically,
Flags: []cli.Flag{
cli.StringFlag{
Name: "format",
Usage: "Specify the output format: text, json",
}, cli.DurationFlag{
Name: "period",
Usage: "Specify the period between heartbeat messages. Valid time units are 'ns', 'us' (or 'µs'), 'ms', 's', 'm', 'h'",
Value: 1 * time.Second,
},
},
},
}
app.RunAndExitOnError()
}