package cmd import ( "fmt" "time" "git.membo.co.uk/dtomlinson/gitlocal/internal/config" "github.com/spf13/cobra" ) var statusCmd = &cobra.Command{ Use: "status", Short: "Show all converted repositories", Long: `Display a list of all repositories that have been converted from .git to .gitlocal.`, RunE: runStatus, } func runStatus(cmd *cobra.Command, args []string) error { cfg, err := config.Load() if err != nil { return fmt.Errorf("failed to load config: %w", err) } if len(cfg.Repos) == 0 { fmt.Println("No converted repositories") return nil } fmt.Printf("Converted Repositories (%d):\n\n", len(cfg.Repos)) for _, repo := range cfg.Repos { fmt.Printf(" %s\n", repo.Path) fmt.Printf(" Converted: %s\n", formatTime(repo.ConvertedAt)) if repo.OriginalRemote != "" { fmt.Printf(" Remote: %s\n", repo.OriginalRemote) } if repo.OriginalBranch != "" { fmt.Printf(" Branch: %s\n", repo.OriginalBranch) } fmt.Println() } return nil } func formatTime(t time.Time) string { now := time.Now() diff := now.Sub(t) switch { case diff < time.Minute: return "just now" case diff < time.Hour: mins := int(diff.Minutes()) if mins == 1 { return "1 minute ago" } return fmt.Sprintf("%d minutes ago", mins) case diff < 24*time.Hour: hours := int(diff.Hours()) if hours == 1 { return "1 hour ago" } return fmt.Sprintf("%d hours ago", hours) case diff < 7*24*time.Hour: days := int(diff.Hours() / 24) if days == 1 { return "1 day ago" } return fmt.Sprintf("%d days ago", days) case diff < 30*24*time.Hour: weeks := int(diff.Hours() / 24 / 7) if weeks == 1 { return "1 week ago" } return fmt.Sprintf("%d weeks ago", weeks) default: months := int(diff.Hours() / 24 / 30) if months == 1 { return "1 month ago" } return fmt.Sprintf("%d months ago", months) } }