Files
kvs-sh/main.go
ryyst 0c9e314d7c refactor: split monolithic main.go into modular structure
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>
2025-10-05 23:34:18 +03:00

96 lines
1.8 KiB
Go

package main
import (
"fmt"
"os"
"strings"
"github.com/chzyer/readline"
)
func main() {
client := NewKVSClient("http://localhost:8090")
// 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")
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")
}
}
}