add support for a standard config in ~/.config/esctl/config.yaml (#7)

This commit is contained in:
T. von Dein
2026-04-29 10:26:53 +02:00
parent 01853c3299
commit f89a09d1d2
3 changed files with 25 additions and 3 deletions

View File

@@ -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.

View File

@@ -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()
}

View File

@@ -85,6 +85,7 @@ func List(conf *cfg.Config) error {
idx++
}
table.Sort()
table.PrintMarkdown()
return nil