From f89a09d1d2705ed74373db3aa8e4e55b023f2885 Mon Sep 17 00:00:00 2001 From: "T. von Dein" Date: Wed, 29 Apr 2026 10:26:53 +0200 Subject: [PATCH] add support for a standard config in ~/.config/esctl/config.yaml (#7) --- README.md | 4 ++++ pkg/cfg/config.go | 23 ++++++++++++++++++++--- pkg/es/cluster.go | 1 + 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0dcdff7..108cbf5 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,10 @@ clusters: pass: asdasdasd ``` +and specify it with `-c configfile`. You may also put clusters into a +default config file in `~/.config/esctl/config.yaml`. In this case you +can omit `-c ...`. + If you want to work on a specific cluster, specify its name with the global `-C` option. diff --git a/pkg/cfg/config.go b/pkg/cfg/config.go index 5a21757..e0e7269 100644 --- a/pkg/cfg/config.go +++ b/pkg/cfg/config.go @@ -30,7 +30,7 @@ import ( ) const ( - Version string = `v0.0.3` + Version string = `v0.0.4` ) type Cluster struct { @@ -57,11 +57,17 @@ func NewConfig() *Config { } func (conf *Config) Init() error { - if conf.ConfigFile != "" { + DefaultConfig := os.Getenv("HOME") + "/.config/esctl/config.yaml" + + switch { + case fileExists(DefaultConfig): + conf.ConfigFile = DefaultConfig + fallthrough + case conf.ConfigFile != "": if err := conf.LoadConfig(); err != nil { return err } - } else { + default: if err := conf.LoadEnv(); err != nil { return err } @@ -165,3 +171,14 @@ func (conf *Config) SetupES() error { return nil } + +func fileExists(filename string) bool { + info, err := os.Stat(filename) + + if err != nil { + // return false on any error + return false + } + + return !info.IsDir() +} diff --git a/pkg/es/cluster.go b/pkg/es/cluster.go index 4175dbd..9c5ccff 100644 --- a/pkg/es/cluster.go +++ b/pkg/es/cluster.go @@ -85,6 +85,7 @@ func List(conf *cfg.Config) error { idx++ } + table.Sort() table.PrintMarkdown() return nil