-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.go
69 lines (64 loc) · 2.16 KB
/
commands.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
package main
import (
"fmt"
"os"
"github.com/kemokemo/gckdir/command"
"github.com/urfave/cli"
)
var (
// GlobalFlags are global flag values
GlobalFlags = []cli.Flag{}
// Commands are sub-commands of this app
Commands = []cli.Command{
{
Name: "generate",
Aliases: []string{"gen"},
Usage: command.UsageGenerate,
Action: command.CmdGenerate,
Flags: []cli.Flag{},
ArgsUsage: "[source] [target]\n\t\tsource: a directory path\n\t\ttarget: a json file path",
OnUsageError: func(c *cli.Context, err error, isSubcommand bool) error {
fmt.Fprintf(c.App.Writer, "A ussage error occurred. Please see '%s %s --help'.\n", c.App.Name, c.Command.FullName())
return err
},
},
{
Name: "verify",
Aliases: []string{"ver"},
Usage: command.UsageVerify,
Action: command.CmdVerify,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "report, r",
Usage: "Create a result report in html format.",
},
cli.StringFlag{
Name: "output, o",
Usage: "Create a report file with the name specified by this flag. Ignored if --report or --open flag is not specified.",
},
cli.BoolFlag{
Name: "open, p",
Usage: "Create and open a result report with the default browser. This option includes the 'report' option.",
},
cli.BoolFlag{
Name: "no-hv, nh",
Usage: "Verify only the file and directory structure. Ignore the each hash value of files.",
},
cli.BoolFlag{
Name: "no-uv, nu",
Usage: "Ignore the unnecessary files.",
},
},
ArgsUsage: "[source] [target]\n\t\tsource: a json file path or a directory path\n\t\ttarget: a directory path",
OnUsageError: func(c *cli.Context, err error, isSubcommand bool) error {
fmt.Fprintf(c.App.Writer, "A ussage error occurred. Please see '%s %s --help'.\n", c.App.Name, c.Command.FullName())
return err
},
},
}
)
// CommandNotFound will be executed when the user inputed sub-command is invalid.
func CommandNotFound(c *cli.Context, subcommand string) {
fmt.Fprintf(os.Stderr, "%s: '%s' is not a %s command. See '%s --help'.\n", c.App.Name, subcommand, c.App.Name, c.App.Name)
os.Exit(command.ExitCodeCommandNotFound)
}