63 lines
1.0 KiB
Go
63 lines
1.0 KiB
Go
package taskwarrior
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
"strings"
|
|
)
|
|
|
|
type TWConfig struct {
|
|
config map[string]string
|
|
}
|
|
|
|
var (
|
|
defaultConfig = map[string]string{
|
|
"uda.tasksquire.report.default": "next",
|
|
"uda.tasksquire.tag.default": "next",
|
|
}
|
|
)
|
|
|
|
func NewConfig(config []string) *TWConfig {
|
|
cfg := parseConfig(config)
|
|
|
|
for key, value := range defaultConfig {
|
|
if _, ok := cfg[key]; !ok {
|
|
cfg[key] = value
|
|
}
|
|
}
|
|
|
|
return &TWConfig{
|
|
config: cfg,
|
|
}
|
|
}
|
|
|
|
func (tc *TWConfig) GetConfig() map[string]string {
|
|
return tc.config
|
|
}
|
|
|
|
func (tc *TWConfig) Get(key string) string {
|
|
if _, ok := tc.config[key]; !ok {
|
|
slog.Debug(fmt.Sprintf("Key not found in config: %s", key))
|
|
return ""
|
|
}
|
|
|
|
return tc.config[key]
|
|
}
|
|
|
|
func parseConfig(config []string) map[string]string {
|
|
configMap := make(map[string]string)
|
|
|
|
for _, line := range config {
|
|
parts := strings.SplitN(line, "=", 2)
|
|
if len(parts) != 2 {
|
|
continue
|
|
}
|
|
key := strings.TrimSpace(parts[0])
|
|
value := strings.TrimSpace(parts[1])
|
|
|
|
configMap[key] = value
|
|
}
|
|
|
|
return configMap
|
|
}
|