go baby go

This commit is contained in:
2025-09-12 19:13:37 -07:00
parent 790360ebb5
commit f4821e9d3f
5 changed files with 49 additions and 15 deletions

View File

@@ -5,6 +5,8 @@ import (
"os"
"github.com/sstent/fitness-tui/internal/config"
"github.com/sstent/fitness-tui/internal/garmin"
"github.com/sstent/fitness-tui/internal/storage"
"github.com/sstent/fitness-tui/internal/tui"
)
@@ -15,9 +17,14 @@ func main() {
os.Exit(1)
}
fmt.Printf("Using storage path: %s\n", cfg.StoragePath)
// Initialize storage
activityStorage := storage.NewActivityStorage(cfg.StoragePath)
app := tui.App{}
// Initialize Garmin client
garminClient := garmin.NewClient(cfg.Garmin.Username, cfg.Garmin.Password, cfg.StoragePath)
// Create and run the application
app := tui.NewApp(activityStorage, garminClient)
if err := app.Run(); err != nil {
fmt.Printf("Application error: %v\n", err)
os.Exit(1)

View File

@@ -2,6 +2,7 @@ package config
import (
"fmt"
"log"
"os"
"path/filepath"
@@ -21,17 +22,37 @@ type Config struct {
}
func Load() (*Config, error) {
// DEBUG: Add diagnostic logging
cwd, _ := os.Getwd()
log.Printf("DEBUG: Current working directory: %s", cwd)
home, _ := os.UserHomeDir()
configDir := filepath.Join(home, ".fitness-tui")
log.Printf("DEBUG: Expected config directory: %s", configDir)
viper.SetConfigName("config")
viper.SetConfigType("yaml")
// Add search paths for config file
viper.AddConfigPath(".") // Current directory
viper.AddConfigPath(configDir) // ~/.fitness-tui/
viper.AddConfigPath(filepath.Join(".", ".fitness-tui")) // ./.fitness-tui/
setViperDefaults()
// Read configuration
if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
log.Printf("DEBUG: Config file not found in search paths")
log.Printf("DEBUG: Searched in: ., %s, ./.fitness-tui/", configDir)
return nil, fmt.Errorf("config file not found - expected config.yaml in: %s", configDir)
} else {
return nil, fmt.Errorf("config read error: %w", err)
}
}
log.Printf("DEBUG: Successfully loaded config from: %s", viper.ConfigFileUsed())
// Create storage path atomically
storagePath := viper.GetString("storagepath")
if err := os.MkdirAll(storagePath, 0755); err != nil {
@@ -74,5 +95,3 @@ func validateConfig(cfg *Config) error {
}
return nil
}
}
}

View File

@@ -5,7 +5,6 @@ import (
"fmt"
"github.com/sstent/fitness-tui/internal/tui/models"
"github.com/sstent/go-garth"
)
type Client struct {

View File

@@ -4,14 +4,26 @@ import (
"fmt"
tea "github.com/charmbracelet/bubbletea"
"github.com/sstent/fitness-tui/internal/garmin"
"github.com/sstent/fitness-tui/internal/storage"
"github.com/sstent/fitness-tui/internal/tui/screens"
)
type App struct {
currentModel tea.Model
}
func NewApp(activityStorage *storage.ActivityStorage, garminClient *garmin.Client) *App {
// Initialize with the activity list screen as the default
activityList := screens.NewActivityList(activityStorage, garminClient)
return &App{
currentModel: activityList,
}
}
func (a *App) Init() tea.Cmd {
return nil
return a.currentModel.Init()
}
func (a *App) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
@@ -22,7 +34,11 @@ func (a *App) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return a, tea.Quit
}
}
return a, nil
// Delegate to the current model
updatedModel, cmd := a.currentModel.Update(msg)
a.currentModel = updatedModel
return a, cmd
}
func (a *App) View() string {

View File

@@ -1,7 +0,0 @@
garmin:
username: "your_garmin_email@example.com"
password: "your_garmin_password"
openrouter:
apikey: "your_openrouter_api_key"
model: "deepseek/deepseek-r1-0528"
storagepath: "/home/sstent/.fitness-tui"