-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
51 lines (42 loc) · 1.71 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
// The main package is the command line runner for the is command.
package main
import (
"os"
"github.com/alecthomas/kong"
"github.com/oalders/is/types"
"github.com/posener/complete"
"github.com/willabides/kongplete"
)
func main() {
var API struct { //nolint:govet
Arch ArchCmd `cmd:"" help:"Check arch e.g. \"is arch like x64\""`
CLI CLICmd `cmd:"" help:"Check cli version. e.g. \"is cli version tmux gte 3\""`
Debug bool `help:"turn on debugging statements"`
FSO FSOCmd `cmd:"" help:"Check fso (file system object). e.g. \"is fso age gte 3 days\""` //nolint:lll
Known KnownCmd `cmd:""`
OS OSCmd `cmd:"" help:"Check OS attributes. e.g. \"is os name eq darwin\""`
There ThereCmd `cmd:"" help:"Check if command exists. e.g. \"is there git\""`
User UserCmd `cmd:"" help:"Info about current user. e.g. \"is user sudoer\""`
Version kong.VersionFlag `help:"Print version to screen"`
InstallCompletions kongplete.InstallCompletions `cmd:"" help:"install shell completions. e.g. \"is install-completions\" and then run the command which is printed to your terminal"` //nolint:lll
}
parser := kong.Must(&API,
kong.Name("is"),
kong.Description("an inspector for your environment"),
kong.UsageOnError(),
kong.Vars{"version": "0.5.2"},
)
// Run kongplete.Complete to handle completion requests
kongplete.Complete(parser,
kongplete.WithPredictor("file", complete.PredictFiles("*")),
)
ctx, err := parser.Parse(os.Args[1:])
parser.FatalIfErrorf(err)
runContext := types.Context{Debug: API.Debug}
err = ctx.Run(&runContext)
ctx.FatalIfErrorf(err)
if runContext.Success {
os.Exit(0)
}
os.Exit(1)
}