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 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 If you want to work on a specific cluster, specify its name with the
global `-C` option. global `-C` option.

View File

@@ -30,7 +30,7 @@ import (
) )
const ( const (
Version string = `v0.0.3` Version string = `v0.0.4`
) )
type Cluster struct { type Cluster struct {
@@ -57,11 +57,17 @@ func NewConfig() *Config {
} }
func (conf *Config) Init() error { 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 { if err := conf.LoadConfig(); err != nil {
return err return err
} }
} else { default:
if err := conf.LoadEnv(); err != nil { if err := conf.LoadEnv(); err != nil {
return err return err
} }
@@ -165,3 +171,14 @@ func (conf *Config) SetupES() error {
return nil 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++ idx++
} }
table.Sort()
table.PrintMarkdown() table.PrintMarkdown()
return nil return nil