Skip to content

Commit 4f6653c

Browse files
committed
support for taskrc location env
Signed-off-by: Jayadeep KM <kmjayadeep@gmail.com>
1 parent 6ce896d commit 4f6653c

6 files changed

Lines changed: 35 additions & 8 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ The server is configured entirely through environment variables.
183183
| `TW_API_PORT` | Server port | `8080` |
184184
| `TW_API_ENABLE_UI` | Enable embedded example UI | `true` |
185185
| `TW_DATA_LOCATION` | Path to Taskwarrior data directory | `~/.task` |
186+
| `TW_TASKRC_LOCATION` | Path to Taskwarrior taskrc file | `~/.taskrc` |
186187
| `TW_API_LOG_LEVEL` | Log level (debug, info, warn, error) | `info` |
187188
| `TW_API_CORS_ENABLED` | Enable CORS | `true` |
188189
| `TW_API_CORS_ORIGINS` | Comma-separated list of allowed origins | `http://localhost:3000` |
@@ -193,6 +194,7 @@ The server is configured entirely through environment variables.
193194
export TW_API_TOKENS="my-secret-token-123,another-token-456"
194195
export TW_API_PORT=8080
195196
export TW_DATA_LOCATION="~/.task"
197+
export TW_TASKRC_LOCATION="~/.taskrc"
196198
export TW_API_LOG_LEVEL="info"
197199
export TW_API_CORS_ORIGINS="http://localhost:3000,https://mytasks.example.com"
198200

cmd/server/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ func main() {
4040

4141
log.Printf("Starting Taskwarrior API server...")
4242
log.Printf("Data location: %s", cfg.Taskwarrior.DataLocation)
43+
log.Printf("Taskrc location: %s", cfg.Taskwarrior.TaskrcLocation)
4344
log.Printf("Server address: %s", cfg.GetAddress())
4445

4546
// Initialize Taskwarrior client
46-
twClient := taskwarrior.NewClient(cfg.Taskwarrior.DataLocation)
47+
twClient := taskwarrior.NewClient(cfg.Taskwarrior.DataLocation, cfg.Taskwarrior.TaskrcLocation)
4748

4849
// Initialize token validator
4950
validator := auth.NewTokenValidator(cfg.Auth.Tokens)

deploy/k8s/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ spec:
3030
value: "8080"
3131
- name: TW_DATA_LOCATION
3232
value: "/root/.task"
33+
- name: TW_TASKRC_LOCATION
34+
value: "/root/.taskrc"
3335
- name: TW_API_LOG_LEVEL
3436
value: "info"
3537
- name: TW_API_CORS_ENABLED

env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ TW_API_ENABLE_UI=true
1414
# Optional: Taskwarrior data location
1515
TW_DATA_LOCATION=~/.task
1616

17+
# Optional: Taskwarrior taskrc location
18+
TW_TASKRC_LOCATION=~/.taskrc
19+
1720
# Optional: Logging
1821
TW_API_LOG_LEVEL=info
1922

internal/config/config.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ type ServerConfig struct {
2525

2626
// TaskwarriorConfig holds Taskwarrior-specific configuration
2727
type TaskwarriorConfig struct {
28-
DataLocation string `yaml:"data_location"`
28+
DataLocation string `yaml:"data_location"`
29+
TaskrcLocation string `yaml:"taskrc_location"`
2930
}
3031

3132
// AuthConfig holds authentication configuration
@@ -54,7 +55,8 @@ func Load() (*Config, error) {
5455
EnableUI: true,
5556
},
5657
Taskwarrior: TaskwarriorConfig{
57-
DataLocation: "~/.task",
58+
DataLocation: "~/.task",
59+
TaskrcLocation: "~/.taskrc",
5860
},
5961
Auth: AuthConfig{
6062
Tokens: []string{},
@@ -98,6 +100,9 @@ func loadFromEnv(config *Config) {
98100
if dataLocation := os.Getenv("TW_DATA_LOCATION"); dataLocation != "" {
99101
config.Taskwarrior.DataLocation = dataLocation
100102
}
103+
if taskrcLocation := os.Getenv("TW_TASKRC_LOCATION"); taskrcLocation != "" {
104+
config.Taskwarrior.TaskrcLocation = taskrcLocation
105+
}
101106

102107
// Auth configuration
103108
if tokensStr := os.Getenv("TW_API_TOKENS"); tokensStr != "" {

internal/taskwarrior/client.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import (
1212

1313
// Client wraps the Taskwarrior CLI
1414
type Client struct {
15-
dataLocation string
15+
dataLocation string
16+
taskrcLocation string
1617
}
1718

1819
// NewClient creates a new Taskwarrior client
19-
func NewClient(dataLocation string) *Client {
20+
func NewClient(dataLocation, taskrcLocation string) *Client {
2021
return &Client{
21-
dataLocation: dataLocation,
22+
dataLocation: dataLocation,
23+
taskrcLocation: taskrcLocation,
2224
}
2325
}
2426

@@ -366,8 +368,20 @@ func (c *Client) buildCommand(args ...string) *exec.Cmd {
366368
}
367369
}
368370

369-
// Prepend data location override
370-
allArgs := append([]string{fmt.Sprintf("rc.data.location=%s", dataLocation)}, args...)
371+
taskrcLocation := c.taskrcLocation
372+
if strings.HasPrefix(taskrcLocation, "~/") {
373+
home, err := os.UserHomeDir()
374+
if err == nil {
375+
taskrcLocation = strings.Replace(taskrcLocation, "~", home, 1)
376+
}
377+
}
378+
379+
// Prepend data location and taskrc location overrides
380+
allArgs := []string{fmt.Sprintf("rc.data.location=%s", dataLocation)}
381+
if taskrcLocation != "" {
382+
allArgs = append(allArgs, fmt.Sprintf("rc:%s", taskrcLocation))
383+
}
384+
allArgs = append(allArgs, args...)
371385
log.Printf("Running command: task %s", strings.Join(allArgs, " "))
372386
cmd := exec.Command("task", allArgs...)
373387
return cmd

0 commit comments

Comments
 (0)