mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 13:04:20 +02:00
Refactor output code, add JSON, TSV and YAML output modes, add -o (#19), add version subcommand
This commit is contained in:
27
cmd/root.go
27
cmd/root.go
@@ -40,9 +40,9 @@ func Main() int {
|
||||
conf := cfg.NewConfig()
|
||||
|
||||
cmd := &cli.Command{
|
||||
Name: "esctl",
|
||||
Usage: "manage elasticsearch from cli",
|
||||
Version: cfg.Version,
|
||||
Name: "esctl",
|
||||
Usage: "manage elasticsearch from cli",
|
||||
//Version: cfg.Version,
|
||||
EnableShellCompletion: true,
|
||||
|
||||
Flags: []cli.Flag{
|
||||
@@ -69,6 +69,13 @@ func Main() int {
|
||||
Usage: "cluster alias to work with",
|
||||
Destination: &conf.CurrentCluster,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "output",
|
||||
Aliases: []string{"o"},
|
||||
Value: "",
|
||||
Usage: "output mode (tsv, markdown, json, yaml) default: tsv",
|
||||
Destination: &conf.Output,
|
||||
},
|
||||
},
|
||||
|
||||
Commands: []*cli.Command{
|
||||
@@ -81,6 +88,7 @@ func Main() int {
|
||||
Node(conf),
|
||||
Doc(conf),
|
||||
Repl(conf),
|
||||
Version(conf),
|
||||
},
|
||||
|
||||
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
|
||||
@@ -101,3 +109,16 @@ func Main() int {
|
||||
|
||||
return Finish(cmd.Run(context.Background(), os.Args))
|
||||
}
|
||||
|
||||
func Version(conf *cfg.Config) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "version",
|
||||
Usage: "show esctl version information",
|
||||
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
_, err := fmt.Printf("esctl version: %s\n build: %s\n branch: %s\n commit: %s\n go version: %s\n API Version: %s\n",
|
||||
cfg.Version, cfg.BUILD, cfg.BRANCH, cfg.COMMIT, cfg.GOVERSION, cfg.APIVERSION)
|
||||
return err
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user