-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.go
52 lines (41 loc) · 1.01 KB
/
cli.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
package usher
import (
"github.com/alecthomas/kong"
)
type WatchCmd struct {
WatchConfig
DirArgs
}
func (c *WatchCmd) Run(globals *Globals) error {
config := GetConfig(globals, &c.DirArgs)
if c.EventBufferSize > 0 {
config.Watch.EventBufferSize = c.EventBufferSize
} else if config.Watch.EventBufferSize == 0 {
config.Watch.EventBufferSize = 1000
}
Watch(config)
return nil
}
type ProcessCmd struct {
DirArgs
}
func (c *ProcessCmd) Run(globals *Globals) error {
config := GetConfig(globals, &c.DirArgs)
Process(config)
return nil
}
var cli struct {
Globals
Watch WatchCmd `cmd:"" help:"Recursively watch a directory for new files and process when they are detected."`
Process ProcessCmd `cmd:"" help:"Recursively process all files in a directory and exit."`
}
func Run(fileMappers map[string]FileMapper) {
SetFileMappers(fileMappers)
ctx := kong.Parse(&cli,
kong.UsageOnError(),
kong.ConfigureHelp(kong.HelpOptions{
Compact: true,
}))
err := ctx.Run(&cli.Globals)
ctx.FatalIfErrorf(err)
}