mirror of
https://github.com/sstent/GarminSync.git
synced 2026-01-26 00:52:32 +00:00
fixing flags
This commit is contained in:
64
cmd/list.go
64
cmd/list.go
@@ -10,6 +10,11 @@ import (
|
||||
"github.com/sstent/garminsync/internal/garmin"
|
||||
)
|
||||
|
||||
// Global flag variables for list command
|
||||
var listAll bool
|
||||
var listMissing bool
|
||||
var listDownloaded bool
|
||||
|
||||
// listCmd represents the list command
|
||||
var listCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
@@ -19,11 +24,6 @@ var listCmd = &cobra.Command{
|
||||
- Missing activities (not yet downloaded)
|
||||
- Downloaded activities`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
// Get flag values
|
||||
listAll, _ := cmd.Flags().GetBool("all")
|
||||
listMissing, _ := cmd.Flags().GetBool("missing")
|
||||
listDownloaded, _ := cmd.Flags().GetBool("downloaded")
|
||||
|
||||
// Initialize config
|
||||
cfg, err := config.LoadConfig()
|
||||
if err != nil {
|
||||
@@ -36,11 +36,11 @@ var listCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
// Initialize database
|
||||
db, err := db.NewDatabase(cfg.DatabasePath)
|
||||
database, err := db.NewDatabase(cfg.DatabasePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to connect to database: %w", err)
|
||||
}
|
||||
defer db.Close()
|
||||
defer database.Close()
|
||||
|
||||
// Get activities from database with pagination
|
||||
page := 1
|
||||
@@ -50,11 +50,11 @@ var listCmd = &cobra.Command{
|
||||
var err error
|
||||
|
||||
if listAll {
|
||||
filteredActivities, err = db.GetAllPaginated(page, pageSize)
|
||||
filteredActivities, err = database.GetAllPaginated(page, pageSize)
|
||||
} else if listMissing {
|
||||
filteredActivities, err = db.GetMissingPaginated(page, pageSize)
|
||||
filteredActivities, err = database.GetMissingPaginated(page, pageSize)
|
||||
} else if listDownloaded {
|
||||
filteredActivities, err = db.GetDownloadedPaginated(page, pageSize)
|
||||
filteredActivities, err = database.GetDownloadedPaginated(page, pageSize)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@@ -62,23 +62,37 @@ var listCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
if len(filteredActivities) == 0 {
|
||||
if page == 1 {
|
||||
fmt.Println("No activities found matching the criteria")
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
// Print activities for current page
|
||||
for _, activity := range filteredActivities {
|
||||
fmt.Printf("Activity ID: %d, Start Time: %s, Filename: %s\n",
|
||||
activity.ActivityId, activity.StartTime.Format("2006-01-02 15:04:05"), activity.Filename)
|
||||
status := "❌ Not Downloaded"
|
||||
if activity.Downloaded {
|
||||
status = "✅ Downloaded"
|
||||
}
|
||||
fmt.Printf("ID: %d | %s | %s | %s\n",
|
||||
activity.ActivityId,
|
||||
activity.StartTime.Format("2006-01-02 15:04:05"),
|
||||
activity.Filename,
|
||||
status)
|
||||
}
|
||||
|
||||
// Prompt to continue or quit
|
||||
fmt.Printf("\nPage %d - Show more? (y/n): ", page)
|
||||
var response string
|
||||
fmt.Scanln(&response)
|
||||
if strings.ToLower(response) != "y" {
|
||||
// Only prompt if there might be more results
|
||||
if len(filteredActivities) == pageSize {
|
||||
fmt.Printf("\nPage %d - Show more? (y/n): ", page)
|
||||
var response string
|
||||
fmt.Scanln(&response)
|
||||
if strings.ToLower(response) != "y" {
|
||||
break
|
||||
}
|
||||
page++
|
||||
} else {
|
||||
break
|
||||
}
|
||||
page++
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -86,17 +100,13 @@ var listCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Ensure rootCmd is properly initialized before adding subcommands
|
||||
if rootCmd == nil {
|
||||
panic("rootCmd must be initialized before adding subcommands")
|
||||
}
|
||||
|
||||
listCmd.Flags().Bool("all", false, "List all activities")
|
||||
listCmd.Flags().Bool("missing", false, "List activities that have not been downloaded")
|
||||
listCmd.Flags().Bool("downloaded", false, "List activities that have been downloaded")
|
||||
// Bind flags to global variables
|
||||
listCmd.Flags().BoolVar(&listAll, "all", false, "List all activities")
|
||||
listCmd.Flags().BoolVar(&listMissing, "missing", false, "List activities that have not been downloaded")
|
||||
listCmd.Flags().BoolVar(&listDownloaded, "downloaded", false, "List activities that have been downloaded")
|
||||
|
||||
listCmd.MarkFlagsMutuallyExclusive("all", "missing", "downloaded")
|
||||
listCmd.MarkFlagsRequiredAtLeastOne("all", "missing", "downloaded")
|
||||
|
||||
rootCmd.AddCommand(listCmd)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user