-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain.go
More file actions
208 lines (183 loc) · 5.99 KB
/
main.go
File metadata and controls
208 lines (183 loc) · 5.99 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package main
import (
"fmt"
"os"
"github.com/johnfox/claudectx/cmd"
"github.com/johnfox/claudectx/internal/store"
)
var version = "dev"
func main() {
// Initialize store
s, err := store.NewStore()
if err != nil {
fmt.Fprintf(os.Stderr, "Error: failed to initialize claudectx: %v\n", err)
os.Exit(1)
}
// Parse arguments
if len(os.Args) < 2 {
// Default action: interactive profile selector
if err := cmd.ListProfilesInteractive(s); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
return
}
arg := os.Args[1]
switch arg {
case "-h", "--help":
printHelp()
case "-v", "--version":
fmt.Printf("claudectx version %s\n", version)
case "-l", "--list":
// Simple list for scripting/piping
if err := cmd.ListProfiles(s); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
case "-c", "--current":
if err := cmd.ShowCurrent(s); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
case "-":
if err := cmd.TogglePrevious(s); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
case "-n":
if len(os.Args) < 3 {
fmt.Fprintln(os.Stderr, "Error: profile name required")
fmt.Fprintln(os.Stderr, "Usage: claudectx -n <name>")
os.Exit(1)
}
if err := cmd.CreateProfile(s, os.Args[2]); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
case "-d":
if len(os.Args) < 3 {
fmt.Fprintln(os.Stderr, "Error: profile name required")
fmt.Fprintln(os.Stderr, "Usage: claudectx -d <name>")
os.Exit(1)
}
if err := cmd.DeleteProfile(s, os.Args[2]); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
case "-r", "--rename":
if len(os.Args) < 4 {
fmt.Fprintln(os.Stderr, "Error: both old and new profile names required")
fmt.Fprintln(os.Stderr, "Usage: claudectx -r <old-name> <new-name>")
os.Exit(1)
}
if err := cmd.RenameProfile(s, os.Args[2], os.Args[3]); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
case "export":
if len(os.Args) < 3 {
fmt.Fprintln(os.Stderr, "Error: profile name required")
fmt.Fprintln(os.Stderr, "Usage: claudectx export <name> [output-file]")
os.Exit(1)
}
profileName := os.Args[2]
outputPath := ""
if len(os.Args) > 3 {
outputPath = os.Args[3]
}
if err := cmd.ExportProfile(s, profileName, outputPath); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
case "import":
inputPath := ""
newName := ""
if len(os.Args) > 2 {
inputPath = os.Args[2]
}
if len(os.Args) > 3 {
newName = os.Args[3]
}
if err := cmd.ImportProfile(s, inputPath, newName); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
case "health":
args := []string{}
if len(os.Args) > 2 {
args = os.Args[2:]
}
if err := cmd.Health(args); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
case "sync":
profileName := ""
if len(os.Args) > 2 {
profileName = os.Args[2]
}
if profileName == "" {
// Sync to current profile
if err := cmd.SyncCurrentProfile(s); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
} else {
// Sync to specified profile
if err := cmd.SyncProfile(s, profileName); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
}
default:
// Assume it's a profile name to switch to
if err := cmd.SwitchProfile(s, arg); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
}
}
func printHelp() {
help := `claudectx - Fast way to switch between Claude Code configuration profiles
USAGE:
claudectx Interactive profile selector (use ↑/↓ arrows)
claudectx <NAME> Switch to profile (auto-syncs current changes first)
claudectx - Switch to previous profile
claudectx -l, --list Simple list (for scripting/piping)
claudectx -c, --current Show current profile
claudectx -n <NAME> Create new profile from current config
claudectx -d <NAME> Delete profile
claudectx -r <OLD> <NEW> Rename profile
claudectx sync [NAME] Sync active config to profile (current if no name)
claudectx export <NAME> [FILE] Export profile to JSON (stdout if no file)
claudectx import [FILE] [NAME] Import profile from JSON (stdin if no file)
claudectx health [NAME] Check profile health (current if no name given)
claudectx -h, --help Show this help
claudectx -v, --version Show version
EXAMPLES:
claudectx Open interactive selector
claudectx work Switch to 'work' profile (auto-syncs changes first)
claudectx - Toggle between current and previous profile
claudectx -l List all profiles (simple output)
claudectx -n personal Create 'personal' profile from current settings
claudectx -d old-work Delete 'old-work' profile
claudectx -r old-name new-name Rename profile from 'old-name' to 'new-name'
claudectx sync Save active config changes to current profile
claudectx sync work Save active config to 'work' profile
claudectx export work work.json Export 'work' profile to file
claudectx export work Export to stdout (for piping)
claudectx import work.json Import profile from file
claudectx import work.json new Import and rename to 'new'
cat work.json | claudectx import Import from stdin
claudectx health Check current profile health
claudectx health work Check 'work' profile health
WHAT CLAUDECTX MANAGES:
- ~/.claude/settings.json User-level settings
- ~/.claude/CLAUDE.md Global instructions
- ~/.claude.json mcpServers User-scoped MCP server configs
- Automatic backups in ~/.claude/backups/
Profiles are stored in ~/.claude/profiles/
Inspired by kubectx - https://github.com/ahmetb/kubectx
`
fmt.Print(help)
}