Skip to content

Commit 94775dc

Browse files
authored
Merge pull request #587 from trycua/feat/cli-version-printout
Fix yargs --version implementation printing "unknown" for built .exe's
2 parents 5fa73fb + fb55b42 commit 94775dc

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

libs/typescript/cua-cli/src/cli.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,27 @@ export async function runCli() {
2222
'\n' +
2323
'Documentation: https://docs.cua.ai/libraries/cua-cli/commands'
2424
);
25+
// version command
26+
argv = argv.command(
27+
'version',
28+
'Show CUA CLI version',
29+
(y) => y,
30+
async () => {
31+
try {
32+
const home = process.env.HOME || process.env.USERPROFILE || '';
33+
const path = `${home}/.cua/bin/.version`;
34+
const version = await Bun.file(path).text();
35+
const v = version.trim();
36+
if (v) {
37+
console.log(v);
38+
} else {
39+
console.log('unknown');
40+
}
41+
} catch {
42+
console.log('unknown');
43+
}
44+
}
45+
);
2546
argv = registerAuthCommands(argv);
2647
argv = registerSandboxCommands(argv);
2748
await argv.demandCommand(1).strict().help().parseAsync();

scripts/install-cli.ps1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,29 @@ function Install-WithBun {
3232

3333
try {
3434
bun add -g @trycua/cli
35+
# Determine installed version from npm registry
36+
try {
37+
$bunVersion = (npm view @trycua/cli version) 2>$null
38+
if (-not $bunVersion) { $bunVersion = "unknown" }
39+
} catch { $bunVersion = "unknown" }
40+
# Ensure install dir and write version file
41+
$installDir = "$env:USERPROFILE\.cua\bin"
42+
if (-not (Test-Path $installDir)) { New-Item -ItemType Directory -Path $installDir -Force | Out-Null }
43+
Set-Content -Path (Join-Path $installDir ".version") -Value $bunVersion -NoNewline
3544
return $true
3645
} catch {
3746
Write-Host "Warning: Failed to install with Bun, trying npm..." -ForegroundColor Yellow
3847
try {
3948
npm install -g @trycua/cli
49+
# Determine installed version from npm registry
50+
try {
51+
$npmVersion = (npm view @trycua/cli version) 2>$null
52+
if (-not $npmVersion) { $npmVersion = "unknown" }
53+
} catch { $npmVersion = "unknown" }
54+
# Ensure install dir and write version file
55+
$installDir = "$env:USERPROFILE\.cua\bin"
56+
if (-not (Test-Path $installDir)) { New-Item -ItemType Directory -Path $installDir -Force | Out-Null }
57+
Set-Content -Path (Join-Path $installDir ".version") -Value $npmVersion -NoNewline
4058
return $true
4159
} catch {
4260
Write-Host "Error: Installation failed with npm as well." -ForegroundColor Red
@@ -106,6 +124,13 @@ try {
106124
}
107125
}
108126

127+
# Write version file for binary install
128+
try {
129+
Set-Content -Path (Join-Path $installDir ".version") -Value $version -NoNewline
130+
} catch {
131+
# Non-fatal
132+
}
133+
109134
# Add to PATH if not already there
110135
$currentPath = [Environment]::GetEnvironmentVariable("Path", "User")
111136
if ($currentPath -notlike "*$installDir*") {

scripts/install-cli.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,15 @@ install_with_bun() {
6363
elif [ -f "$HOME/.profile" ]; then
6464
config_file="$HOME/.profile"
6565
fi
66-
67-
print_success "cua" "$VERSION" "$config_file"
66+
# Determine installed version via npm registry (fallback to unknown)
67+
local VERSION_BUN
68+
VERSION_BUN=$(npm view @trycua/cli version 2>/dev/null || echo "unknown")
69+
# Write version file to ~/.cua/bin/.version
70+
local INSTALL_DIR="$HOME/.cua/bin"
71+
mkdir -p "$INSTALL_DIR"
72+
echo "$VERSION_BUN" > "$INSTALL_DIR/.version"
73+
# Print success and exit
74+
print_success "$(command -v cua)" "$VERSION_BUN" "$config_file"
6875
exit 0
6976
else
7077
echo "❌ Installation failed. Please try installing manually:"
@@ -114,6 +121,7 @@ VERSION=${TAG_NAME#cua-v}
114121
# Find the binary URL in the release assets
115122
BINARY_URL=$(echo "$LATEST_RELEASE" | grep -o 'https://.*/download/[^"]*/'${BINARY_NAME}'"' | head -1)
116123
BINARY_URL="${BINARY_URL%\"}"
124+
printf "\033[90mBINARY_URL: %s\033[0m\n" "$BINARY_URL"
117125

118126
if [ -z "$BINARY_URL" ]; then
119127
echo "⚠️ Could not find ${BINARY_NAME} in release assets, falling back to Bun installation"
@@ -136,6 +144,9 @@ fi
136144
# Make the binary executable
137145
chmod +x "$INSTALL_DIR/cua"
138146

147+
# Write version file
148+
echo "$VERSION" > "$INSTALL_DIR/.version"
149+
139150
# Add ~/.cua/bin to PATH if not already in PATH
140151
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
141152
# Add to .bashrc, .zshrc, or .profile

0 commit comments

Comments
 (0)