-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.go
More file actions
91 lines (77 loc) · 2.26 KB
/
Copy pathmain.go
File metadata and controls
91 lines (77 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"flag"
"fmt"
"log/slog"
"os"
tea "charm.land/bubbletea/v2"
"github.com/armanjr/polyclaude/internal/config"
"github.com/armanjr/polyclaude/internal/tui"
"github.com/armanjr/polyclaude/internal/updater"
)
var version = "dev"
func printUsage() {
fmt.Printf(`PolyClaude %s
Schedule multiple Claude Code Pro accounts to minimize rate-limit downtime.
Usage:
polyclaude Launch the interactive setup wizard
polyclaude update Download and install the latest version
polyclaude --dry-run Preview the wizard without making changes
polyclaude --version Print version and exit
polyclaude --help Show this help
`, version)
}
func main() {
// Handle "update" subcommand before flag parsing
if len(os.Args) > 1 && os.Args[1] == "update" {
if err := updater.SelfUpdate(version); err != nil {
fmt.Fprintf(os.Stderr, "Update failed: %v\n", err)
os.Exit(1)
}
os.Exit(0)
}
// Handle flags manually for clean help output
if len(os.Args) > 1 {
switch os.Args[1] {
case "--version", "-version":
fmt.Println("polyclaude " + version)
os.Exit(0)
case "--help", "-help", "-h":
printUsage()
os.Exit(0)
}
}
dryRun := flag.Bool("dry-run", false, "")
flag.Usage = printUsage
flag.Parse()
// Check for updates (cached, non-blocking)
homeDir, _ := config.DefaultHomeDir()
if latest := updater.CheckCached(version, homeDir); latest != "" {
fmt.Printf("Update available: v%s -> %s (run `polyclaude update` to upgrade)\n\n", version, latest)
}
// Set up debug logging to file (bubbletea owns the terminal)
f, err := tea.LogToFile("polyclaude-debug.log", "polyclaude")
if err != nil {
fmt.Fprintf(os.Stderr, "error setting up log file: %v\n", err)
os.Exit(1)
}
defer f.Close()
slog.Info("starting polyclaude", "dry_run", *dryRun)
// Check for existing config
if config.Exists(homeDir) && !*dryRun {
fmt.Print("Existing configuration found at " + config.ConfigPath(homeDir) + "\n")
fmt.Print("Start fresh? [Y/n] ")
var answer string
fmt.Scanln(&answer)
if answer != "" && answer != "y" && answer != "Y" {
fmt.Println("Exiting.")
os.Exit(0)
}
}
m := tui.New(*dryRun)
p := tea.NewProgram(m)
if _, err := p.Run(); err != nil {
slog.Error("program error", "error", err)
os.Exit(1)
}
}