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>
This commit is contained in:
9
main.go
9
main.go
@@ -10,6 +10,9 @@ import (
|
||||
|
||||
// executeCommand executes a single command line
|
||||
func (c *KVSClient) executeCommand(line string) bool {
|
||||
// Expand variables in the line
|
||||
line = c.expandVariables(line)
|
||||
|
||||
parts := parseCommand(line)
|
||||
if len(parts) == 0 {
|
||||
return true
|
||||
@@ -66,6 +69,12 @@ func (c *KVSClient) executeCommand(line string) bool {
|
||||
c.handleImport(args)
|
||||
case "export-list":
|
||||
c.handleExportList(args)
|
||||
case "set":
|
||||
c.handleSet(args)
|
||||
case "unset":
|
||||
c.handleUnset(args)
|
||||
case "vars":
|
||||
c.handleVars(args)
|
||||
case "batch", "source":
|
||||
c.handleBatch(args, c.executeCommand)
|
||||
default:
|
||||
|
Reference in New Issue
Block a user