From 76ad6c7afac99bdb7257e9601125ed73ffb1d021 Mon Sep 17 00:00:00 2001 From: "T. von Dein" Date: Wed, 8 Jul 2026 14:13:47 +0200 Subject: [PATCH] remove workaround to load config in root.Before() (#83) see: https://github.com/urfave/cli/issues/2348 --- cmd/api.go | 2 +- cmd/ccr.go | 4 ++-- cmd/ccr_follower.go | 14 +++++++------- cmd/cluster.go | 2 +- cmd/cluster_reroute.go | 8 ++++---- cmd/cluster_settings.go | 2 +- cmd/completion.go | 9 +-------- cmd/datastream.go | 10 +++++----- cmd/ilm.go | 2 +- cmd/index.go | 10 +++++----- cmd/index_alias.go | 6 +++--- cmd/index_template.go | 4 ++-- cmd/node.go | 4 ++-- cmd/roles.go | 2 +- 14 files changed, 36 insertions(+), 43 deletions(-) diff --git a/cmd/api.go b/cmd/api.go index 5ccd5d0..beccd6f 100644 --- a/cmd/api.go +++ b/cmd/api.go @@ -72,7 +72,7 @@ func ApiShow(conf *cfg.Config) *cli.Command { }, ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Capi) + complete(conf, cmd, Capi) }, } } diff --git a/cmd/ccr.go b/cmd/ccr.go index 4eb536c..8a28c87 100644 --- a/cmd/ccr.go +++ b/cmd/ccr.go @@ -59,7 +59,7 @@ func CcrStatus(conf *cfg.Config) *cli.Command { }, ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Ccluster) + complete(conf, cmd, Ccluster) }, Action: func(ctx context.Context, cmd *cli.Command) error { @@ -115,7 +115,7 @@ func CcrRemoteInfo(conf *cfg.Config) *cli.Command { UsageText: "info [options] []", ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cindex) + complete(conf, cmd, Cindex) }, Action: func(ctx context.Context, cmd *cli.Command) error { diff --git a/cmd/ccr_follower.go b/cmd/ccr_follower.go index ea1c811..cd809dd 100644 --- a/cmd/ccr_follower.go +++ b/cmd/ccr_follower.go @@ -60,7 +60,7 @@ func CcrFollowerRenew(conf *cfg.Config) *cli.Command { }, ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cindex) + complete(conf, cmd, Cindex) }, Action: func(ctx context.Context, cmd *cli.Command) error { @@ -82,7 +82,7 @@ func CcrFollowerResume(conf *cfg.Config) *cli.Command { UsageText: "resume [options] ", ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cindex) + complete(conf, cmd, Cindex) }, Action: func(ctx context.Context, cmd *cli.Command) error { @@ -104,7 +104,7 @@ func CcrFollowerPause(conf *cfg.Config) *cli.Command { UsageText: "pause [options] ", ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cindex) + complete(conf, cmd, Cindex) }, Action: func(ctx context.Context, cmd *cli.Command) error { @@ -126,7 +126,7 @@ func CcrFollowerUnfollow(conf *cfg.Config) *cli.Command { UsageText: "unfollow [options] ", ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cindex) + complete(conf, cmd, Cindex) }, Action: func(ctx context.Context, cmd *cli.Command) error { @@ -158,7 +158,7 @@ func CcrFollowerAdd(conf *cfg.Config) *cli.Command { }, ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cindex) + complete(conf, cmd, Cindex) }, Action: func(ctx context.Context, cmd *cli.Command) error { @@ -181,7 +181,7 @@ func CcrFollowerDelete(conf *cfg.Config) *cli.Command { UsageText: "delete ", ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cindex) + complete(conf, cmd, Cindex) }, Action: func(ctx context.Context, cmd *cli.Command) error { @@ -205,7 +205,7 @@ func CcrFollowerShow(conf *cfg.Config) *cli.Command { UsageText: "show ", ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cindex) + complete(conf, cmd, Cindex) }, Action: func(ctx context.Context, cmd *cli.Command) error { diff --git a/cmd/cluster.go b/cmd/cluster.go index fc3cbd6..1fdc445 100644 --- a/cmd/cluster.go +++ b/cmd/cluster.go @@ -83,7 +83,7 @@ func ClusterSwitch(conf *cfg.Config) *cli.Command { Aliases: []string{"ctx"}, ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Ccluster) + complete(conf, cmd, Ccluster) }, Action: func(ctx context.Context, cmd *cli.Command) error { diff --git a/cmd/cluster_reroute.go b/cmd/cluster_reroute.go index 3518fb8..b5cb0ed 100644 --- a/cmd/cluster_reroute.go +++ b/cmd/cluster_reroute.go @@ -50,7 +50,7 @@ func ClusterRerouteMove(conf *cfg.Config) *cli.Command { UsageText: "move [options] ", ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cindex) + complete(conf, cmd, Cindex) }, Flags: []cli.Flag{ @@ -95,7 +95,7 @@ func ClusterRerouteAllocateReplica(conf *cfg.Config) *cli.Command { UsageText: "allocate-replica [options] ", ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cindex) + complete(conf, cmd, Cindex) }, Flags: []cli.Flag{ @@ -133,7 +133,7 @@ func ClusterRerouteCancel(conf *cfg.Config) *cli.Command { UsageText: "cancel [options] ", ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cindex) + complete(conf, cmd, Cindex) }, Flags: []cli.Flag{ @@ -185,7 +185,7 @@ func ClusterRerouteAllocatePrimary(conf *cfg.Config, stale bool) *cli.Command { UsageText: name + " [options] ", ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cindex) + complete(conf, cmd, Cindex) }, Flags: []cli.Flag{ diff --git a/cmd/cluster_settings.go b/cmd/cluster_settings.go index ccb45d1..dde3036 100644 --- a/cmd/cluster_settings.go +++ b/cmd/cluster_settings.go @@ -105,7 +105,7 @@ func ClusterSettingsSet(conf *cfg.Config) *cli.Command { }, ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cclustersettings) + complete(conf, cmd, Cclustersettings) }, Action: func(ctx context.Context, cmd *cli.Command) error { diff --git a/cmd/completion.go b/cmd/completion.go index 3862765..ca647d0 100644 --- a/cmd/completion.go +++ b/cmd/completion.go @@ -36,18 +36,11 @@ const ( Cclustersettings ) -func complete(cmd *cli.Command, what int) { +func complete(conf *cfg.Config, cmd *cli.Command, what int) { if cmd.NArg() > 0 { return } - // FIXME: config should load from root.Before(), see https://github.com/urfave/cli/issues/2348 - // workaround: load it directly here - conf := cfg.NewConfig() - if err := conf.Init(); err != nil { - return - } - var ( list []string err error diff --git a/cmd/datastream.go b/cmd/datastream.go index fbe067b..55be913 100644 --- a/cmd/datastream.go +++ b/cmd/datastream.go @@ -91,7 +91,7 @@ func DatastreamShow(conf *cfg.Config) *cli.Command { }, ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cdatastream) + complete(conf, cmd, Cdatastream) }, } } @@ -113,7 +113,7 @@ func DatastreamCreate(conf *cfg.Config) *cli.Command { }, ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cdatastream) + complete(conf, cmd, Cdatastream) }, } } @@ -135,7 +135,7 @@ func DatastreamDelete(conf *cfg.Config) *cli.Command { }, ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cdatastream) + complete(conf, cmd, Cdatastream) }, } } @@ -148,7 +148,7 @@ func DatastreamRollover(conf *cfg.Config) *cli.Command { UsageText: "rollover ", ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cindex) + complete(conf, cmd, Cindex) }, Flags: []cli.Flag{ @@ -205,7 +205,7 @@ func DatastreamIlm(conf *cfg.Config) *cli.Command { UsageText: "ds ilm ", ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cdatastream) + complete(conf, cmd, Cdatastream) }, Action: func(ctx context.Context, cmd *cli.Command) error { diff --git a/cmd/ilm.go b/cmd/ilm.go index e999de5..c10c5e1 100644 --- a/cmd/ilm.go +++ b/cmd/ilm.go @@ -123,7 +123,7 @@ func IlmShow(conf *cfg.Config) *cli.Command { }, ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cilm) + complete(conf, cmd, Cilm) }, } } diff --git a/cmd/index.go b/cmd/index.go index 03bb624..67f19e9 100644 --- a/cmd/index.go +++ b/cmd/index.go @@ -110,7 +110,7 @@ func IndexShow(conf *cfg.Config) *cli.Command { }, ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cindex) + complete(conf, cmd, Cindex) }, } } @@ -180,7 +180,7 @@ func IndexDelete(conf *cfg.Config) *cli.Command { UsageText: "delete ", ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cindex) + complete(conf, cmd, Cindex) }, Action: func(ctx context.Context, cmd *cli.Command) error { @@ -201,7 +201,7 @@ func IndexClose(conf *cfg.Config) *cli.Command { UsageText: "close ", ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cindex) + complete(conf, cmd, Cindex) }, Action: func(ctx context.Context, cmd *cli.Command) error { @@ -243,7 +243,7 @@ func IndexFields(conf *cfg.Config) *cli.Command { }, ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cindex) + complete(conf, cmd, Cindex) }, Action: func(ctx context.Context, cmd *cli.Command) error { @@ -264,7 +264,7 @@ func IndexIlm(conf *cfg.Config) *cli.Command { UsageText: "index ilm ", ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cindex) + complete(conf, cmd, Cindex) }, Action: func(ctx context.Context, cmd *cli.Command) error { diff --git a/cmd/index_alias.go b/cmd/index_alias.go index b490f60..7d9ab02 100644 --- a/cmd/index_alias.go +++ b/cmd/index_alias.go @@ -52,7 +52,7 @@ func IndexAliasCreate(conf *cfg.Config) *cli.Command { UsageText: "create ", ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cindex) + complete(conf, cmd, Cindex) }, Action: func(ctx context.Context, cmd *cli.Command) error { @@ -76,7 +76,7 @@ func IndexAliasDelete(conf *cfg.Config) *cli.Command { UsageText: "delete ", ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cindex) + complete(conf, cmd, Cindex) }, Action: func(ctx context.Context, cmd *cli.Command) error { @@ -100,7 +100,7 @@ func IndexAliasRollover(conf *cfg.Config) *cli.Command { UsageText: "rollover ", ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cindex) + complete(conf, cmd, Cindex) }, Flags: []cli.Flag{ diff --git a/cmd/index_template.go b/cmd/index_template.go index ae66d6e..0dc2891 100644 --- a/cmd/index_template.go +++ b/cmd/index_template.go @@ -71,7 +71,7 @@ func IndexTemplateShow(conf *cfg.Config) *cli.Command { }, ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cindex) + complete(conf, cmd, Cindex) }, } } @@ -215,7 +215,7 @@ func IndexTemplateDelete(conf *cfg.Config) *cli.Command { }, ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cindex) + complete(conf, cmd, Cindex) }, } } diff --git a/cmd/node.go b/cmd/node.go index 46d62f1..9c34f64 100644 --- a/cmd/node.go +++ b/cmd/node.go @@ -60,7 +60,7 @@ func NodeShow(conf *cfg.Config) *cli.Command { UsageText: "show [options] ", ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cnode) + complete(conf, cmd, Cnode) }, Action: func(ctx context.Context, cmd *cli.Command) error { @@ -90,7 +90,7 @@ func NodeClients(conf *cfg.Config) *cli.Command { }, ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Cnode) + complete(conf, cmd, Cnode) }, Action: func(ctx context.Context, cmd *cli.Command) error { diff --git a/cmd/roles.go b/cmd/roles.go index 8d4d480..519b62b 100644 --- a/cmd/roles.go +++ b/cmd/roles.go @@ -68,7 +68,7 @@ func RoleShow(conf *cfg.Config) *cli.Command { UsageText: "show [options] ", ShellComplete: func(ctx context.Context, cmd *cli.Command) { - complete(cmd, Crole) + complete(conf, cmd, Crole) }, Action: func(ctx context.Context, cmd *cli.Command) error {