Initial commit
This commit is contained in:
43
taskwarrior/config.go
Normal file
43
taskwarrior/config.go
Normal file
@ -0,0 +1,43 @@
|
||||
package taskwarrior
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type TWConfig struct {
|
||||
config map[string]string
|
||||
}
|
||||
|
||||
func NewConfig(config []string) *TWConfig {
|
||||
return &TWConfig{
|
||||
config: parseConfig(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
|
||||
}
|
||||
Reference in New Issue
Block a user