83 lines
2.2 KiB
Go
83 lines
2.2 KiB
Go
package config
|
|
|
|
import "path/filepath"
|
|
|
|
const (
|
|
// AppName is used for config/data directory names under XDG paths.
|
|
AppName = "task-master"
|
|
// CliName is the installed binary / command name.
|
|
CliName = "tm"
|
|
DefaultProject = "inbox"
|
|
DefaultTheme = "default"
|
|
configFileName = "config.json"
|
|
|
|
envHome = "TASK_MASTER_HOME"
|
|
envDataDir = "TASK_MASTER_DATA_DIR"
|
|
)
|
|
|
|
// Config holds application settings persisted under ~/.config/task-master.
|
|
type Config struct {
|
|
ActiveProject string `json:"activeProject"`
|
|
DataDir string `json:"dataDir"`
|
|
Theme string `json:"theme"`
|
|
// ProjectLists maps project ID → comma-separated board list ids
|
|
// (e.g. "all" or "backlog,in_progress").
|
|
ProjectLists map[string]string `json:"projectLists,omitempty"`
|
|
}
|
|
|
|
// Path returns the absolute path to the config file.
|
|
func Path(home string) string {
|
|
return filepath.Join(home, ".config", AppName, configFileName)
|
|
}
|
|
|
|
// DefaultDataDir returns the default data directory under ~/.local/share.
|
|
func DefaultDataDir(home string) string {
|
|
return filepath.Join(home, ".local", "share", AppName)
|
|
}
|
|
|
|
// Defaults returns a Config with sensible defaults for the given home directory.
|
|
func Defaults(home string) Config {
|
|
return Config{
|
|
ActiveProject: DefaultProject,
|
|
DataDir: DefaultDataDir(home),
|
|
Theme: DefaultTheme,
|
|
ProjectLists: map[string]string{},
|
|
}
|
|
}
|
|
|
|
// ApplyDefaults fills empty fields from defaults without overwriting set values.
|
|
func (c *Config) ApplyDefaults(home string) {
|
|
d := Defaults(home)
|
|
if c.ActiveProject == "" {
|
|
c.ActiveProject = d.ActiveProject
|
|
}
|
|
if c.DataDir == "" {
|
|
c.DataDir = d.DataDir
|
|
}
|
|
if c.Theme == "" {
|
|
c.Theme = d.Theme
|
|
}
|
|
if c.ProjectLists == nil {
|
|
c.ProjectLists = map[string]string{}
|
|
}
|
|
}
|
|
|
|
// ActiveBoardLists returns the persisted board filter string for a project (default: "all").
|
|
func (c *Config) ActiveBoardLists(projectID string) string {
|
|
if c.ProjectLists == nil {
|
|
return "all"
|
|
}
|
|
if v, ok := c.ProjectLists[projectID]; ok && v != "" {
|
|
return v
|
|
}
|
|
return "all"
|
|
}
|
|
|
|
// SetActiveBoardLists stores the board filter string for a project.
|
|
func (c *Config) SetActiveBoardLists(projectID, listIDs string) {
|
|
if c.ProjectLists == nil {
|
|
c.ProjectLists = map[string]string{}
|
|
}
|
|
c.ProjectLists[projectID] = listIDs
|
|
}
|