-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
cli.go
59 lines (50 loc) · 1.18 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
53
54
55
56
57
58
59
package probe
import (
"github.com/mintoolkit/mint/pkg/app"
"github.com/mintoolkit/mint/pkg/app/master/command"
"github.com/urfave/cli/v2"
)
//Standalone probing
const (
Name = "probe"
Usage = "Probe target endpoint"
Alias = "prb"
)
var CLI = &cli.Command{
Name: Name,
Aliases: []string{Alias},
Usage: Usage,
Flags: append([]cli.Flag{
cflag(FlagTarget),
cflag(FlagPort),
}, command.HTTPProbeFlagsBasic()...),
Action: func(ctx *cli.Context) error {
gparams, ok := command.CLIContextGet(ctx.Context, command.GlobalParams).(*command.GenericParams)
if !ok || gparams == nil {
return command.ErrNoGlobalParams
}
xc := app.NewExecutionContext(
Name,
gparams.QuietCLIMode,
gparams.OutputFormat)
targetEndpoint := ctx.String(FlagTarget)
if targetEndpoint == "" {
if ctx.Args().Len() < 1 {
xc.Out.Error("param.target", "missing target")
cli.ShowCommandHelp(ctx, Name)
return nil
} else {
targetEndpoint = ctx.Args().First()
}
}
httpProbeOpts := command.GetHTTPProbeOptions(xc, ctx, true)
targetPorts := ctx.UintSlice(FlagPort)
OnCommand(
xc,
gparams,
targetEndpoint,
targetPorts,
httpProbeOpts)
return nil
},
}