forked from ahoy-cli/ahoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flag.go
58 lines (50 loc) · 1.25 KB
/
flag.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
package main
import (
"flag"
"github.com/codegangsta/cli"
)
var globalFlags = []cli.Flag{
cli.BoolFlag{
Name: "verbose, v",
Usage: "Output extra details like the commands to be run.",
EnvVar: "AHOY_VERBOSE",
Destination: &verbose,
},
cli.StringFlag{
Name: "file, f",
Usage: "Use a specific ahoy file.",
Destination: &sourcefile,
},
cli.BoolFlag{
Name: "help, h",
Usage: "show help",
},
cli.BoolFlag{
Name: "version",
Usage: "print the version",
},
cli.BoolFlag{
Name: "generate-bash-completion",
},
}
func flagSet(name string, flags []cli.Flag) *flag.FlagSet {
set := flag.NewFlagSet(name, flag.ContinueOnError)
for _, f := range flags {
f.Apply(set)
}
return set
}
func initFlags(incomingFlags []string) {
// Reset the sourcedir for when we're testing. Otherwise the global state
// is preserved between the tests.
AhoyConf.srcDir = ""
// Grab the global flags first ourselves so we can customize the yaml file loaded.
// Flags are only parsed once, so we need to do this before cli has the chance to?
tempFlags := flagSet("tempFlags", globalFlags)
tempFlags.Parse(incomingFlags)
}
func overrideFlags(app *cli.App) {
app.Flags = globalFlags
app.HideVersion = true
app.HideHelp = true
}