Files
kvs-sh/cmd_system.go
ryyst efaa5cdcc9 feat: add shell scripting with variables
Implemented roadmap #9: Shell scripts execution with variables.

Features:
- set <name> <value> - Set shell variable
- unset <name> - Remove variable
- vars - List all variables
- Variable substitution in all commands

Variable syntax:
- $VAR or ${VAR} - Shell variables
- $ENV:VARNAME - Environment variables

Variables expand before command execution, enabling:
- Dynamic key paths: put $BASE/$ID '{"data":"value"}'
- Reusable values: set TOKEN xyz && auth $TOKEN
- Script parameterization in batch files

Example batch script:
  set USER alice
  set KEY_PREFIX users
  put $KEY_PREFIX/$USER '{"name":"$USER"}'
  get $KEY_PREFIX/$USER

Variables are session-scoped and work in both interactive
and batch modes. Environment variables can be injected using
$ENV:HOME syntax.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-06 00:01:36 +03:00

89 lines
2.8 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
Export/Import:
export <file> <key1> ... - Export keys to JSON file
export-list <keyfile> <output> - Export keys listed in file
import <file> - Import keys from JSON file
--skip-existing - Skip existing keys (default)
--overwrite - Overwrite existing keys
Shell Scripting:
set <name> <value> - Set shell variable
unset <name> - Remove shell variable
vars - List all variables
Variables: $VAR or ${VAR}
Environment: $ENV:VARNAME
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)
}