-
Notifications
You must be signed in to change notification settings - Fork 1
/
pounce.go
51 lines (41 loc) · 967 Bytes
/
pounce.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
package main
import (
"fmt"
"os"
"github.com/urfave/cli/v2"
)
var version string // set by linker
var app = cli.App{
UseShortOptionHandling: true,
EnableBashCompletion: true,
Version: version,
Flags: append(append(commonFlags, collectFlags...), applyFlags...),
Action: func(c *cli.Context) error {
if dir := commonConfig.dir; dir != "" {
if err := os.Chdir(dir); err != nil {
return fmt.Errorf("chdir: %w", err)
}
}
args := c.Args().Slice()
if commonConfig.collect && commonConfig.apply ||
(!commonConfig.collect && !commonConfig.apply) {
// both
return both(os.Stderr, args)
}
if commonConfig.collect {
// collect only
return collect(os.Stdout, os.Stderr, args)
}
if commonConfig.apply {
// apply only
return apply(os.Stdin)
}
return nil
},
}
func main() {
if err := app.Run(os.Args); err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
}