forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.go
44 lines (35 loc) · 1.25 KB
/
run.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
package cmd
import (
"flag"
"os"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/elastic/beats/libbeat/beat"
)
func genRunCmd(name, version string, beatCreator beat.Creator, runFlags *pflag.FlagSet) *cobra.Command {
runCmd := cobra.Command{
Use: "run",
Short: "Run " + name,
Run: func(cmd *cobra.Command, args []string) {
err := beat.Run(name, version, beatCreator)
if err != nil {
os.Exit(1)
}
},
}
// Run subcommand flags, only available to *beat run
runCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("N"))
runCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("httpprof"))
runCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("cpuprofile"))
runCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("memprofile"))
// TODO deprecate in favor of subcommands (7.0):
runCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("configtest"))
runCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("setup"))
runCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("version"))
runCmd.Flags().MarkDeprecated("version", "version flag has been deprectad, use version subcommand")
runCmd.Flags().MarkDeprecated("configtest", "setup flag has been deprectad, use configtest subcommand")
if runFlags != nil {
runCmd.Flags().AddFlagSet(runFlags)
}
return &runCmd
}