Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions cmd/todoist/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ You can either:
return err
}

out.WriteSuccess(fmt.Sprintf("Authenticated successfully. Config saved to %s", config.ConfigPath()))
configPath, _ := config.ConfigPath() // Error already handled by Save()
out.WriteSuccess(fmt.Sprintf("Authenticated successfully. Config saved to %s", configPath))
return nil
},
}
Expand All @@ -70,7 +71,10 @@ You can either:
Short: "Remove stored credentials",
RunE: func(cmd *cobra.Command, args []string) error {
out := output.NewFormatter(os.Stdout, flags.asJSON)
path := config.ConfigPath()
path, err := config.ConfigPath()
if err != nil {
return err
}
if err := os.Remove(path); err != nil {
if os.IsNotExist(err) {
out.WriteSuccess("No credentials stored.")
Expand Down
16 changes: 0 additions & 16 deletions cmd/todoist/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"os"
"strings"

"github.com/buddyh/todoist-cli/internal/api"
"github.com/buddyh/todoist-cli/internal/output"
Expand Down Expand Up @@ -98,18 +97,3 @@ func newReopenCmd(flags *rootFlags) *cobra.Command {

return cmd
}

// Helper for comma-separated string to slice
func splitLabels(s string) []string {
if s == "" {
return nil
}
parts := strings.Split(s, ",")
result := make([]string, 0, len(parts))
for _, p := range parts {
if t := strings.TrimSpace(p); t != "" {
result = append(result, t)
}
}
return result
}
6 changes: 5 additions & 1 deletion cmd/todoist/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ func newViewCmd(flags *rootFlags) *cobra.Command {
if err == nil && len(comments) > 0 {
fmt.Printf("\nComments (%d):\n", len(comments))
for _, c := range comments {
fmt.Printf(" [%s] %s\n", c.PostedAt[:10], c.Content)
date := c.PostedAt
if len(date) >= 10 {
date = date[:10]
}
fmt.Printf(" [%s] %s\n", date, c.Content)
}
}

Expand Down
32 changes: 24 additions & 8 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@ type Config struct {
}

// ConfigDir returns the config directory path
func ConfigDir() string {
home, _ := os.UserHomeDir()
return filepath.Join(home, configDirName)
func ConfigDir() (string, error) {
home, err := os.UserHomeDir()
if err != nil {
return "", fmt.Errorf("failed to determine home directory: %w", err)
}
return filepath.Join(home, configDirName), nil
}

// ConfigPath returns the full config file path
func ConfigPath() string {
return filepath.Join(ConfigDir(), configFileName)
func ConfigPath() (string, error) {
dir, err := ConfigDir()
if err != nil {
return "", err
}
return filepath.Join(dir, configFileName), nil
}

// Load loads the configuration from disk
Expand All @@ -36,7 +43,10 @@ func Load() (*Config, error) {
}

// Then try config file
path := ConfigPath()
path, err := ConfigPath()
if err != nil {
return nil, err
}
data, err := os.ReadFile(path)
if err != nil {
if os.IsNotExist(err) {
Expand All @@ -59,7 +69,10 @@ func Load() (*Config, error) {

// Save saves the configuration to disk
func Save(cfg *Config) error {
dir := ConfigDir()
dir, err := ConfigDir()
if err != nil {
return err
}
if err := os.MkdirAll(dir, 0700); err != nil {
return fmt.Errorf("failed to create config dir: %w", err)
}
Expand All @@ -69,7 +82,10 @@ func Save(cfg *Config) error {
return fmt.Errorf("failed to marshal config: %w", err)
}

path := ConfigPath()
path, err := ConfigPath()
if err != nil {
return err
}
if err := os.WriteFile(path, data, 0600); err != nil {
return fmt.Errorf("failed to write config: %w", err)
}
Expand Down
6 changes: 5 additions & 1 deletion internal/output/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,11 @@ func (f *Formatter) WriteCompletedTasks(resp *api.CompletedTasksResponse) error
}

for _, t := range resp.Items {
fmt.Fprintf(f.w, "\033[90m%s\033[0m \033[9m%s\033[0m\n", t.CompletedAt[:10], t.Content)
date := t.CompletedAt
if len(date) >= 10 {
date = date[:10]
}
fmt.Fprintf(f.w, "\033[90m%s\033[0m \033[9m%s\033[0m\n", date, t.Content)
}

return nil
Expand Down