mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 11:54:18 +02:00
generate command tree from within (esctl --show-command-tree)
This commit is contained in:
166
README.md
166
README.md
@@ -61,87 +61,91 @@ Features:
|
|||||||
Command tree:
|
Command tree:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
api
|
api - api access and documentation
|
||||||
list
|
list - list index of API calls
|
||||||
repl
|
show - show an API doc
|
||||||
show
|
repl - interactive API repl
|
||||||
ccr
|
ccr - manage cross cluster replication
|
||||||
follower
|
status - cross cluster replication status (yaml config with 2 clusters required)
|
||||||
add
|
pause - pause shard allocation
|
||||||
delete
|
resume - resume shard allocation
|
||||||
pause
|
follower - manage ccr follower indices
|
||||||
renew
|
show - show ccr follower index details
|
||||||
resume
|
add - add ccr follower index
|
||||||
show
|
delete - delete ccr follower index
|
||||||
unfollow
|
unfollow - unfollow ccr follower index
|
||||||
info
|
pause - pause ccr index to follow
|
||||||
pause
|
resume - resume ccr index to follow
|
||||||
resume
|
renew - renew ccr follower index
|
||||||
status
|
info - show ccr remote info
|
||||||
cluster
|
cluster - manage cluster[s]
|
||||||
list
|
status - show cluster status
|
||||||
settings
|
list - list configured clusters
|
||||||
list
|
settings - cluster settings management
|
||||||
set
|
list - show cluster settings
|
||||||
status
|
set - set|update cluster settings
|
||||||
datastream
|
datastream - manage data streams
|
||||||
create
|
list - list indicies
|
||||||
delete
|
show - show details about an data stream
|
||||||
list
|
create - create a new data stream
|
||||||
rollover
|
delete - delete a data stream
|
||||||
show
|
rollover - roll over a data stream
|
||||||
debug
|
doc - manage documents
|
||||||
doc
|
add - add JSON document index
|
||||||
add
|
show - show a JSON document
|
||||||
delete
|
delete - delete JSON document[s] from index[es]
|
||||||
show
|
ilm - manage index lifecycle
|
||||||
help
|
retry - retry applying an ILM profile to an index
|
||||||
help-jsonpath
|
status - get the current index lifecycle management status
|
||||||
ilm
|
list - list index lifecycle policies
|
||||||
create
|
show - show details about an index lifecycle policy
|
||||||
list
|
create - create a index lifecycle policy
|
||||||
retry
|
index - manage indicies
|
||||||
show
|
list - list indicies
|
||||||
status
|
show - show details about an index
|
||||||
index
|
create - create a new index
|
||||||
alias
|
delete - delete an index
|
||||||
create
|
close - close an index
|
||||||
delete
|
allocation - explain index allocation
|
||||||
list
|
modify - modify an index
|
||||||
rollover
|
fields - show info about field capabilities
|
||||||
allocation
|
ilm - show ilm status
|
||||||
close
|
alias - manage index aliases
|
||||||
create
|
create - create an index alias
|
||||||
delete
|
list - list index aliases
|
||||||
fields
|
delete - delete an index alias
|
||||||
ilm
|
rollover - roll over an index alias
|
||||||
list
|
template - manage index templates
|
||||||
modify
|
list - list index templates
|
||||||
show
|
show - show details about an index template
|
||||||
template
|
create - create a new index template
|
||||||
create
|
modify - modify a new index template
|
||||||
delete
|
delete - delete an index template
|
||||||
list
|
node - manage nodes
|
||||||
modify
|
list - list nodes
|
||||||
show
|
show - show details about a node
|
||||||
node
|
role - manage roles
|
||||||
list
|
list - list roles
|
||||||
show
|
show - show details about a role
|
||||||
role
|
diff - show differences between roles and CSV baseline
|
||||||
diff
|
search - search within an index
|
||||||
list
|
shard - manage shards
|
||||||
show
|
list - list shards
|
||||||
search
|
show - show details about a shard
|
||||||
shard
|
snapshot - manage snapshots
|
||||||
list
|
list - list snapshots
|
||||||
show
|
show - show details about a snapshot
|
||||||
snapshot
|
task - manage tasks
|
||||||
list
|
list - list tasks
|
||||||
show
|
cancel - cancel running task
|
||||||
task
|
version - show esctl version information
|
||||||
cancel
|
debug - developer only
|
||||||
list
|
help-jsonpath - show jsonpath help
|
||||||
version
|
completion - Output shell completion script for bash, zsh, fish, or Powershell
|
||||||
|
bash - Output bash completion script
|
||||||
|
zsh - Output zsh completion script
|
||||||
|
fish - Output fish completion script
|
||||||
|
pwsh - Output pwsh completion script
|
||||||
```
|
```
|
||||||
|
|
||||||
Configure `esctl` with environment variables:
|
Configure `esctl` with environment variables:
|
||||||
|
|||||||
55
cmd/root.go
55
cmd/root.go
@@ -22,6 +22,7 @@ import (
|
|||||||
golog "log"
|
golog "log"
|
||||||
"os"
|
"os"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"codeberg.org/scip/esctl/pkg/cfg"
|
"codeberg.org/scip/esctl/pkg/cfg"
|
||||||
"codeberg.org/scip/esctl/pkg/es"
|
"codeberg.org/scip/esctl/pkg/es"
|
||||||
@@ -41,11 +42,11 @@ func Finish(err error) int {
|
|||||||
|
|
||||||
func Main() int {
|
func Main() int {
|
||||||
conf := cfg.NewConfig()
|
conf := cfg.NewConfig()
|
||||||
|
tree := false
|
||||||
|
|
||||||
cmd := &cli.Command{
|
cmd := &cli.Command{
|
||||||
Name: "esctl",
|
Name: "esctl",
|
||||||
Usage: "manage elasticsearch from cli",
|
Usage: "manage elasticsearch from cli",
|
||||||
//Version: cfg.Version,
|
|
||||||
EnableShellCompletion: true,
|
EnableShellCompletion: true,
|
||||||
|
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
@@ -63,6 +64,13 @@ func Main() int {
|
|||||||
Usage: "enable HTTP debugging",
|
Usage: "enable HTTP debugging",
|
||||||
Destination: &conf.DebugHTTP,
|
Destination: &conf.DebugHTTP,
|
||||||
},
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "show-command-tree",
|
||||||
|
Value: false,
|
||||||
|
Usage: "generate a command tree",
|
||||||
|
Destination: &tree,
|
||||||
|
Hidden: true,
|
||||||
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "config",
|
Name: "config",
|
||||||
Aliases: []string{"c"},
|
Aliases: []string{"c"},
|
||||||
@@ -94,25 +102,30 @@ func Main() int {
|
|||||||
},
|
},
|
||||||
|
|
||||||
Commands: []*cli.Command{
|
Commands: []*cli.Command{
|
||||||
Search(conf),
|
Api(conf),
|
||||||
Cluster(conf),
|
|
||||||
Ccr(conf),
|
Ccr(conf),
|
||||||
Index(conf),
|
Cluster(conf),
|
||||||
Ilm(conf),
|
|
||||||
Datastream(conf),
|
Datastream(conf),
|
||||||
|
Doc(conf),
|
||||||
|
Ilm(conf),
|
||||||
|
Index(conf),
|
||||||
|
Node(conf),
|
||||||
|
Roles(conf),
|
||||||
|
Search(conf),
|
||||||
Shard(conf),
|
Shard(conf),
|
||||||
Snapshot(conf),
|
Snapshot(conf),
|
||||||
Node(conf),
|
Task(conf),
|
||||||
Doc(conf),
|
|
||||||
Version(conf),
|
Version(conf),
|
||||||
Debug(conf),
|
Debug(conf),
|
||||||
Roles(conf),
|
|
||||||
Task(conf),
|
|
||||||
HelpJsonPath(conf),
|
HelpJsonPath(conf),
|
||||||
Api(conf),
|
|
||||||
},
|
},
|
||||||
|
|
||||||
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
|
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
|
||||||
|
if tree {
|
||||||
|
Tree(cmd)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
if err := conf.Init(); err != nil {
|
if err := conf.Init(); err != nil {
|
||||||
if len(os.Args) > 1 {
|
if len(os.Args) > 1 {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -237,3 +250,25 @@ func Debug(conf *cfg.Config) *cli.Command {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Tree(cmd *cli.Command) error {
|
||||||
|
max := 20
|
||||||
|
|
||||||
|
cmd.Walk(func(cmd *cli.Command) error {
|
||||||
|
path := cmd.Path()
|
||||||
|
command := path[len(path)-1]
|
||||||
|
|
||||||
|
if len(path) == 1 || command == "help" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
indent := strings.Repeat(" ", len(path[1:])-1)
|
||||||
|
space := strings.Repeat(" ", max-(len(command)+len(indent)))
|
||||||
|
|
||||||
|
fmt.Printf("%s%s %s - %s\n", indent, command, space, cmd.Usage)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -32,7 +32,7 @@ require (
|
|||||||
github.com/olekukonko/tablewriter v1.1.4
|
github.com/olekukonko/tablewriter v1.1.4
|
||||||
github.com/tidwall/gjson v1.19.0
|
github.com/tidwall/gjson v1.19.0
|
||||||
github.com/tlinden/yadu v0.1.3
|
github.com/tlinden/yadu v0.1.3
|
||||||
github.com/urfave/cli/v3 v3.9.1-0.20260524212652-be8b79d0c8de
|
github.com/urfave/cli/v3 v3.10.1-0.20260623012112-f980ca84bf65
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -189,6 +189,8 @@ github.com/tlinden/yadu v0.1.3 h1:5cRCUmj+l5yvlM2irtpFBIJwVV2DPEgYSaWvF19FtcY=
|
|||||||
github.com/tlinden/yadu v0.1.3/go.mod h1:l3bRmHKL9zGAR6pnBHY2HRPxBecf7L74BoBgOOpTcUA=
|
github.com/tlinden/yadu v0.1.3/go.mod h1:l3bRmHKL9zGAR6pnBHY2HRPxBecf7L74BoBgOOpTcUA=
|
||||||
github.com/urfave/cli/v3 v3.9.1-0.20260524212652-be8b79d0c8de h1:ESKPiS7inVoBnv4FmgGNZdjWBI/wmvaragoyD3D9nM4=
|
github.com/urfave/cli/v3 v3.9.1-0.20260524212652-be8b79d0c8de h1:ESKPiS7inVoBnv4FmgGNZdjWBI/wmvaragoyD3D9nM4=
|
||||||
github.com/urfave/cli/v3 v3.9.1-0.20260524212652-be8b79d0c8de/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
|
github.com/urfave/cli/v3 v3.9.1-0.20260524212652-be8b79d0c8de/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
|
||||||
|
github.com/urfave/cli/v3 v3.10.1-0.20260623012112-f980ca84bf65 h1:NXitXXO9DupDLEFj8hIyYtsubRxSFTp5JXqohElT0nU=
|
||||||
|
github.com/urfave/cli/v3 v3.10.1-0.20260623012112-f980ca84bf65/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
|
||||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
|
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
|
||||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
|
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
|
||||||
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
||||||
|
|||||||
Reference in New Issue
Block a user