mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 07:54:17 +02:00
add support for a standard config in ~/.config/esctl/config.yaml (#7)
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
@@ -85,6 +85,7 @@ func List(conf *cfg.Config) error {
|
||||
idx++
|
||||
}
|
||||
|
||||
table.Sort()
|
||||
table.PrintMarkdown()
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user