-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds configuration file support.
- Loading branch information
1 parent
114340b
commit b000c45
Showing
3 changed files
with
86 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters