Refactor output code, add JSON, TSV and YAML output modes, add -o (#19), add version subcommand

This commit is contained in:
T. von Dein
2026-05-20 13:06:39 +02:00
parent 32de4863af
commit 0870ceb3df
16 changed files with 439 additions and 190 deletions

View File

@@ -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
},
}
}