Implemented roadmap #1: Configuration file for persistent profiles. Features: - Auto-saves profiles to ~/.kvs/config.json on add/use/remove - Auto-loads profiles on shell startup - File created with 0600 permissions for token security - Shows active profile in welcome message - Added 'profile save' and 'profile load' commands for manual control Technical details: - Created config.go with LoadConfig/SaveConfig functions - Profile changes automatically trigger persistence - ~/.kvs directory created with 0700 permissions if missing - Gracefully handles missing config file on first run 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
96 lines
2.2 KiB
Go
96 lines
2.2 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])
|
|
c.saveProfiles()
|
|
|
|
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])
|
|
c.saveProfiles()
|
|
|
|
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])
|
|
c.saveProfiles()
|
|
|
|
case "save":
|
|
if err := c.saveProfiles(); err != nil {
|
|
fmt.Println(red("Error saving profiles:"), err)
|
|
return
|
|
}
|
|
fmt.Println(green("Profiles saved to ~/.kvs/config.json"))
|
|
|
|
case "load":
|
|
config, err := LoadConfig()
|
|
if err != nil {
|
|
fmt.Println(red("Error loading profiles:"), err)
|
|
return
|
|
}
|
|
c.syncConfigToClient(config)
|
|
fmt.Println(green("Profiles loaded from ~/.kvs/config.json"))
|
|
if c.activeProfile != "" {
|
|
fmt.Println(cyan("Active profile:"), c.activeProfile)
|
|
}
|
|
|
|
default:
|
|
fmt.Println(red("Unknown profile command:"), subCmd)
|
|
fmt.Println("Available commands: add, use, remove, save, load")
|
|
}
|
|
}
|