-
Notifications
You must be signed in to change notification settings - Fork 17
/
config.go
43 lines (38 loc) · 954 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"fmt"
"os"
"path/filepath"
"k8s.io/apimachinery/pkg/util/yaml"
)
type Config struct {
Quiet bool `yaml:"quiet"`
NoColor bool `yaml:"noColor"`
Raw bool `yaml:"raw"`
Timestamps bool `yaml:"timestamps"`
ColorMode string `yaml:"colorMode"`
ColorScheme string `yaml:"colorScheme"`
TemplateString string `yaml:"templateString"`
KubeConfigPath string `yaml:"kubeConfigPath"`
}
func (c *Config) LoadDefault() error {
home := os.Getenv("HOME")
if home == "" {
return nil
}
if err := c.LoadFromPath(filepath.Join(home, ".config", "ktail", "config.yml")); err != nil &&
!os.IsNotExist(err) {
return err
}
return nil
}
func (c *Config) LoadFromPath(path string) error {
data, err := os.ReadFile(path)
if err != nil {
return err
}
if err := yaml.UnmarshalStrict(data, c); err != nil {
return fmt.Errorf("parsing config file %q: %w", path, err)
}
return nil
}