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>
104 lines
2.0 KiB
Go
104 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/chzyer/readline"
|
|
)
|
|
|
|
func main() {
|
|
client := NewKVSClient("http://localhost:8090")
|
|
|
|
// Load saved profiles
|
|
if config, err := LoadConfig(); err == nil {
|
|
client.syncConfigToClient(config)
|
|
}
|
|
|
|
// Setup readline
|
|
rl, err := readline.NewEx(&readline.Config{
|
|
Prompt: cyan("kvs> "),
|
|
HistoryFile: os.Getenv("HOME") + "/.kvs_history",
|
|
AutoComplete: completer,
|
|
InterruptPrompt: "^C",
|
|
EOFPrompt: "exit",
|
|
})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer rl.Close()
|
|
|
|
fmt.Println(magenta("KVS Interactive Shell"))
|
|
fmt.Println("Type 'help' for available commands")
|
|
if client.activeProfile != "" {
|
|
fmt.Println(green("Active profile:"), client.activeProfile)
|
|
}
|
|
fmt.Println()
|
|
|
|
for {
|
|
line, err := rl.Readline()
|
|
if err != nil {
|
|
break
|
|
}
|
|
|
|
line = strings.TrimSpace(line)
|
|
if line == "" {
|
|
continue
|
|
}
|
|
|
|
parts := parseCommand(line)
|
|
if len(parts) == 0 {
|
|
continue
|
|
}
|
|
|
|
cmd := parts[0]
|
|
args := parts[1:]
|
|
|
|
switch cmd {
|
|
case "exit", "quit":
|
|
fmt.Println("Goodbye!")
|
|
return
|
|
case "clear":
|
|
print("\033[H\033[2J")
|
|
case "help":
|
|
client.handleHelp(args)
|
|
case "connect":
|
|
client.handleConnect(args)
|
|
case "auth":
|
|
client.handleAuth(args)
|
|
case "profile":
|
|
client.handleProfile(args)
|
|
case "get":
|
|
client.handleGet(args)
|
|
case "put":
|
|
client.handlePut(args)
|
|
case "delete":
|
|
client.handleDelete(args)
|
|
case "meta":
|
|
client.handleMeta(args)
|
|
case "members":
|
|
client.handleMembers(args)
|
|
case "health":
|
|
client.handleHealth(args)
|
|
case "user":
|
|
if len(args) > 0 {
|
|
switch args[0] {
|
|
case "get":
|
|
client.handleUserGet(args[1:])
|
|
case "create":
|
|
client.handleUserCreate(args[1:])
|
|
default:
|
|
fmt.Println(red("Unknown user command:"), args[0])
|
|
fmt.Println("Type 'help' for available commands")
|
|
}
|
|
} else {
|
|
client.handleUserList(args)
|
|
}
|
|
default:
|
|
fmt.Println(red("Unknown command:"), cmd)
|
|
fmt.Println("Type 'help' for available commands")
|
|
}
|
|
}
|
|
}
|