-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
101 lines (92 loc) · 2.52 KB
/
main.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
package main
import (
"fmt"
"os"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
const (
PROG = `contextdir`
)
var (
// version, commit, date, builtBy are provided by goreleaser during build
version = "dev"
commit = "none"
date = "unknown"
builtBy = "unknown"
)
func init() {
cli.VersionPrinter = func(c *cli.Context) {
fmt.Printf("version %s, commit %s, built at %s by %s\n", version, commit, date, builtBy)
}
log.SetFormatter(&log.TextFormatter{
DisableLevelTruncation: true,
TimestampFormat: "2006-01-02T15:04:05Z07:00",
FullTimestamp: true})
}
func main() {
app := &cli.App{
Name: PROG,
Version: version,
EnableBashCompletion: true,
Usage: "Utility for working with local Docker build context directories",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "verbosity",
// fixme: in a future release, urfave/cli has automatic textwrap support
Usage: "Sets the verbosity level of the log messages printed by the program, should be\n" +
`one of: "debug", "error", "fatal", "info", "panic", "trace", or "warn"`,
Action: func(c *cli.Context, verbosity string) error {
level, err := log.ParseLevel(verbosity)
if err != nil {
return err
}
log.SetLevel(level)
return err
},
},
},
Commands: []*cli.Command{
{
Name: "list",
Aliases: []string{"ls"},
Usage: "list the contents of the given context dir, honoring .dockerignore (if found)",
ArgsUsage: "[dir]",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "ignored",
Usage: "Instead of the normal output, only list files in the given contextdir(s) which\n" +
"match patterns in the .dockerignore file",
},
&cli.BoolFlag{
Name: "detailed",
Usage: "Format the output in JSON format with detailed information about the files (may\n" +
"be combined with the --ignored flag)",
},
},
Action: handleListCmd,
},
{
Name: "checksum",
Aliases: []string{"sum", "hash"},
Usage: "list the contents of the given context path(s), excluding any paths mentioned in\n" +
".dockerignore",
ArgsUsage: "[dir]",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "json",
Usage: "Format the output in JSON format",
},
&cli.BoolFlag{
Name: "detailed",
Usage: "Report the entire scan in JSON format",
},
},
Action: handleChecksumCmd,
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}