Files
kvs-sh/cmd_system.go
ryyst 2f77c0a825 feat: add batch command execution from files
Implemented roadmap #3: Batch operations from file.

Features:
- batch <file> or source <file> - Execute commands from script file
- Skips empty lines and comments (lines starting with #)
- Shows line numbers during execution for easy debugging
- Blocks exit/quit commands in batch mode (won't exit shell)
- Displays execution summary with counts

Implementation:
- Refactored main loop to extract executeCommand() method
- Created cmd_batch.go with batch file processor
- Reads file line by line, processes each command
- Summary shows total lines, executed count, and skipped count

Example batch file:
  # Connect and setup
  connect http://localhost:8080
  auth <token>

  # Batch insert
  put key1 '{"data":"value1"}'
  put key2 '{"data":"value2"}'

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-05 23:54:47 +03:00

75 lines
2.3 KiB
Go

package main
import "fmt"
func (c *KVSClient) handleConnect(args []string) {
if len(args) < 1 {
fmt.Println(red("Usage: connect <base-url>"))
return
}
c.baseURL = args[0]
fmt.Println(green("Connected to:"), c.baseURL)
}
func (c *KVSClient) handleAuth(args []string) {
if len(args) < 1 {
fmt.Println(red("Usage: auth <token>"))
return
}
c.currentToken = args[0]
fmt.Println(green("Authentication token set"))
}
func (c *KVSClient) handleHelp(args []string) {
help := `
KVS Interactive Shell - Available Commands:
Connection & Authentication:
connect <url> - Connect to KVS server
auth <token> - Set authentication token
profile - List all profiles
profile add <name> <token> <user-uuid> [url] - Add user profile
profile use <name> - Switch to user profile
profile remove <name> - Remove user profile
profile save - Save profiles to ~/.kvs/config.json
profile load - Load profiles from ~/.kvs/config.json
Key-Value Operations:
get <key> - Retrieve value for key
put <key> <json> - Store JSON value at key
delete <key> - Delete key
Resource Metadata:
meta get <key> - Get metadata (owner, group) for a key
meta set <key> [flags] - Set metadata for a key
Flags: --owner <uuid>, --group <uuid>, --permissions <number>
Cluster Management:
members - List cluster members
health - Check service health
User Management:
user get <uuid> - Get user details
user create <nickname> - Create new user (admin only)
Group Management:
group create <name> [members] - Create new group
group get <uuid> - Get group details
group update <uuid> <members> - Replace all group members
group delete <uuid> - Delete group
group add-member <uuid> <user-uuid> - Add member to group
group remove-member <uuid> <user-uuid> - Remove member from group
Batch Operations:
batch <file> - Execute commands from file
source <file> - Alias for batch
--continue-on-error - Continue execution even if commands fail
System:
help - Show this help
exit, quit - Exit shell
clear - Clear screen
`
fmt.Println(help)
}