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