36 lines
1.1 KiB
Plaintext
36 lines
1.1 KiB
Plaintext
|
|
#!/usr/bin/env nu
|
||
|
|
# install.nu — install a built artifact to ~/.local/bin.
|
||
|
|
# Reads JSON inputs from stdin (built-artifact).
|
||
|
|
# Emits JSON result to stdout.
|
||
|
|
|
||
|
|
def main []: nothing -> nothing {
|
||
|
|
let inputs = ($in | from json)
|
||
|
|
let artifact = ($inputs | get "built-artifact")
|
||
|
|
|
||
|
|
if (not ($artifact.ok)) {
|
||
|
|
error make { msg: "built-artifact.ok is false — refusing to install" }
|
||
|
|
}
|
||
|
|
|
||
|
|
let src = $artifact.path
|
||
|
|
let target = ($nu.home-dir | path join ".local" "bin" $artifact.crate_name)
|
||
|
|
|
||
|
|
let cp_result = (do { ^cp $src $target } | complete)
|
||
|
|
if ($cp_result.exit_code != 0) {
|
||
|
|
error make { msg: $"cp failed: ($cp_result.stderr)" }
|
||
|
|
}
|
||
|
|
|
||
|
|
let chmod_result = (do { ^chmod +x $target } | complete)
|
||
|
|
if ($chmod_result.exit_code != 0) {
|
||
|
|
error make { msg: $"chmod failed: ($chmod_result.stderr)" }
|
||
|
|
}
|
||
|
|
|
||
|
|
let version_result = (do { nu -c $"($target) --version" } | complete)
|
||
|
|
let version = if ($version_result.exit_code == 0) {
|
||
|
|
$version_result.stdout | str trim
|
||
|
|
} else {
|
||
|
|
"unknown"
|
||
|
|
}
|
||
|
|
|
||
|
|
{ "installed": { ok: true, binary_path: $target, version: $version } } | to json | print
|
||
|
|
}
|