Refactored 800+ line main.go into clean, domain-separated files: - main.go (96 lines) - Entry point and command router only - types.go - Type definitions and data structures - client.go - HTTP client and request handling - cmd_kv.go - Key-value operations (get/put/delete) - cmd_meta.go - Resource metadata commands - cmd_user.go - User management commands - cmd_profile.go - Profile management - cmd_cluster.go - Cluster operations (members/health) - cmd_system.go - System commands (connect/auth/help) - utils.go - Shared utilities (parsing, colors, completion) No functional changes, pure reorganization for maintainability. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
70 lines
1.5 KiB
Go
70 lines
1.5 KiB
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
func (c *KVSClient) handleProfile(args []string) {
|
|
if len(args) == 0 {
|
|
// List profiles
|
|
if len(c.profiles) == 0 {
|
|
fmt.Println(yellow("No profiles configured"))
|
|
return
|
|
}
|
|
fmt.Println(cyan("Available profiles:"))
|
|
for name, profile := range c.profiles {
|
|
marker := " "
|
|
if name == c.activeProfile {
|
|
marker = "*"
|
|
}
|
|
fmt.Printf("%s %s (user: %s, url: %s)\n", marker, name, profile.UserUUID, profile.BaseURL)
|
|
}
|
|
return
|
|
}
|
|
|
|
subCmd := args[0]
|
|
switch subCmd {
|
|
case "add":
|
|
if len(args) < 4 {
|
|
fmt.Println(red("Usage: profile add <name> <token> <user-uuid> [base-url]"))
|
|
return
|
|
}
|
|
baseURL := c.baseURL
|
|
if len(args) >= 5 {
|
|
baseURL = args[4]
|
|
}
|
|
c.profiles[args[1]] = Profile{
|
|
Name: args[1],
|
|
Token: args[2],
|
|
UserUUID: args[3],
|
|
BaseURL: baseURL,
|
|
}
|
|
fmt.Println(green("Profile added:"), args[1])
|
|
|
|
case "use":
|
|
if len(args) < 2 {
|
|
fmt.Println(red("Usage: profile use <name>"))
|
|
return
|
|
}
|
|
profile, ok := c.profiles[args[1]]
|
|
if !ok {
|
|
fmt.Println(red("Profile not found:"), args[1])
|
|
return
|
|
}
|
|
c.currentToken = profile.Token
|
|
c.currentUser = profile.UserUUID
|
|
c.baseURL = profile.BaseURL
|
|
c.activeProfile = args[1]
|
|
fmt.Println(green("Switched to profile:"), args[1])
|
|
|
|
case "remove":
|
|
if len(args) < 2 {
|
|
fmt.Println(red("Usage: profile remove <name>"))
|
|
return
|
|
}
|
|
delete(c.profiles, args[1])
|
|
if c.activeProfile == args[1] {
|
|
c.activeProfile = ""
|
|
}
|
|
fmt.Println(green("Profile removed:"), args[1])
|
|
}
|
|
}
|