-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.sh
More file actions
executable file
·60 lines (50 loc) · 1.62 KB
/
Copy pathcli.sh
File metadata and controls
executable file
·60 lines (50 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bash
set -euo pipefail
###############################################################################
# cli.sh — Coin Smith: PSBT transaction builder CLI
#
# Usage:
# ./cli.sh <fixture.json>
#
# Writes JSON report to out/<fixture_name>.json
# Exit 0 on success, 1 on error
###############################################################################
error_json() {
local code="$1"
local message="$2"
printf '{"ok":false,"error":{"code":"%s","message":"%s"}}\n' "$code" "$message"
}
if [[ $# -lt 1 ]]; then
error_json "INVALID_ARGS" "Usage: cli.sh <fixture.json>"
echo "Error: No fixture file provided" >&2
exit 1
fi
FIXTURE="$1"
if [[ ! -f "$FIXTURE" ]]; then
error_json "FILE_NOT_FOUND" "Fixture file not found: $FIXTURE"
echo "Error: Fixture file not found: $FIXTURE" >&2
exit 1
fi
# Create output directory
mkdir -p out
# Derive output filename from fixture basename
# e.g. fixtures/basic_change_p2wpkh.json → out/basic_change_p2wpkh.json
FIXTURE_NAME="$(basename "$FIXTURE")"
OUTPUT_FILE="out/$FIXTURE_NAME"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Locate bun (may be installed to ~/.bun/bin by setup.sh)
BUN="bun"
if ! command -v bun &>/dev/null; then
if [[ -x "$HOME/.bun/bin/bun" ]]; then
BUN="$HOME/.bun/bin/bun"
else
ERR=$(error_json "MISSING_RUNTIME" "bun is not installed. Run setup.sh first.")
echo "$ERR" > "$OUTPUT_FILE"
echo "Error: bun not found" >&2
exit 1
fi
fi
# Run the TypeScript CLI via Bun
# Logs go to stderr; output is written to $OUTPUT_FILE by the script itself
"$BUN" run "$SCRIPT_DIR/src/cli.ts" "$FIXTURE" "$OUTPUT_FILE"
exit $?