52 lines
1.9 KiB
Text
52 lines
1.9 KiB
Text
# provisioning-tool child-process client.
|
|
# Spawns the binary at PROVISIONING_TOOL_BIN (default: provisioning-tool in PATH)
|
|
# and returns structured output. Used as the second fallback tier when the daemon is absent.
|
|
|
|
const TOOL_DEFAULT_BIN = "provisioning-tool"
|
|
|
|
# Resolve the binary path.
|
|
def tool-bin []: nothing -> string {
|
|
$env.PROVISIONING_TOOL_BIN? | default $TOOL_DEFAULT_BIN
|
|
}
|
|
|
|
# Return true when the binary is present in PATH or at PROVISIONING_TOOL_BIN.
|
|
export def ptool-available []: nothing -> bool {
|
|
let r = (do { ^which (tool-bin) } | complete)
|
|
$r.exit_code == 0
|
|
}
|
|
|
|
# List all registered tools via `provisioning-tool list`.
|
|
# Returns a list of records with fields: name, description, category.
|
|
export def ptool-list [
|
|
--category: string = "" # filter by category (read/mutation/destructive/admin)
|
|
]: nothing -> list<record> {
|
|
let args = if ($category | is-empty) {
|
|
["list", "--compact"]
|
|
} else {
|
|
["list", "--category", $category, "--compact"]
|
|
}
|
|
let r = (do { run-external (tool-bin) ...$args } | complete)
|
|
if $r.exit_code != 0 { error make {msg: $"ptool-list failed: ($r.stderr)"} }
|
|
$r.stdout | from json | get tools? | default []
|
|
}
|
|
|
|
# Show JSON Schema for a named tool.
|
|
export def ptool-schema [name: string]: nothing -> record {
|
|
let r = (do { run-external (tool-bin) "schema" $name "--compact" } | complete)
|
|
if $r.exit_code != 0 { error make {msg: $"ptool-schema ($name) failed: ($r.stderr)"} }
|
|
$r.stdout | from json
|
|
}
|
|
|
|
# Invoke a tool by name with params record.
|
|
# Returns the result record or errors if the tool fails.
|
|
export def ptool-invoke [
|
|
name: string
|
|
params: record
|
|
]: nothing -> record {
|
|
let params_json = ($params | to json --raw)
|
|
let r = (do {
|
|
run-external (tool-bin) "invoke" $name "--params" $params_json "--compact"
|
|
} | complete)
|
|
if $r.exit_code != 0 { error make {msg: $"ptool-invoke ($name) failed: ($r.stderr)"} }
|
|
$r.stdout | from json
|
|
}
|