Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Once installed and authenticated, try:

```bash
decodo scrape https://ip.decodo.com
decodo search "top articles hacker news" --limit 5 --parse
decodo google-search "top articles hacker news" --limit 5 --parse
```

You should see markdown or parsed JSON within seconds. If you see an auth error, double-check your
Expand Down Expand Up @@ -207,7 +207,7 @@ decodo google-search "query" --format ndjson --full | jq -c '.results[]'

```bash
# Search and extract titles
decodo search "rust web scraping" --limit 3 --parse | jq '.[].title'
decodo google-search "rust web scraping" --limit 3 --parse | jq '.[].title'

# Scrape JSON API endpoint
decodo scrape https://ip.decodo.com/json | jq '.ip'
Expand All @@ -221,7 +221,7 @@ decodo screenshot https://example.com -o shot.png
```bash
# Request from a specific country
decodo scrape https://example.com --country us
decodo search "shoes" --geo de --parse
decodo search "shoes" --geo de
decodo google-search "shoes" --geo de --parse
```

Expand Down
64 changes: 51 additions & 13 deletions docs/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ $ErrorActionPreference = 'Stop'

$PackageName = '@decodo/cli'
$CommandName = 'decodo'
$CommandAlias = 'dcd'
$MinNodeMajor = 18

function Write-Info([string]$Message) {
Expand Down Expand Up @@ -51,14 +50,44 @@ if (-not (Get-Command npm -ErrorAction SilentlyContinue)) {
Write-Err 'npm is not available. Install npm and try again.'
}

Write-Info "Installing $PackageName globally..."
npm install -g $PackageName
$UserPrefix = $null

# Run npm install without aborting on failure, so we can fall back. Returns the exit code.
function Invoke-NpmInstall {
param([string[]]$NpmArgs)
try {
& npm install -g @NpmArgs | Out-Host
return $LASTEXITCODE
} catch {
return 1
}
}

function Install-Package {
Write-Info "Installing $PackageName globally..."
if ((Invoke-NpmInstall @($PackageName)) -eq 0) {
return
}

Write-Warn 'Global install failed. Falling back to a user-level install.'
$script:UserPrefix = Join-Path $env:APPDATA 'npm-global'
New-Item -ItemType Directory -Force -Path $script:UserPrefix | Out-Null
Write-Info "Installing $PackageName to $script:UserPrefix instead..."
if ((Invoke-NpmInstall @('--prefix', $script:UserPrefix, $PackageName)) -ne 0) {
Write-Err @"
Installation failed.
Try fixing your npm permissions, or run the CLI without installing: npx $PackageName --help
"@
}

$env:PATH = "$script:UserPrefix;$env:PATH"
}

Install-Package

$installedVersion = $null
if (Get-Command $CommandName -ErrorAction SilentlyContinue) {
$installedVersion = & $CommandName --version 2>$null
} elseif (Get-Command $CommandAlias -ErrorAction SilentlyContinue) {
$installedVersion = & $CommandAlias --version 2>$null
}

if ($installedVersion) {
Expand All @@ -68,21 +97,30 @@ if ($installedVersion) {
Write-Host ''
Write-Host 'Installed! You may need to restart your shell or add the npm global bin directory to your PATH.' -ForegroundColor Green

$npmPrefix = (npm prefix -g 2>$null).Trim()
if ($npmPrefix) {
$pathEntries = $env:PATH -split ';' | Where-Object { $_ -ne '' }
if ($pathEntries -notcontains $npmPrefix) {
Write-Warn "$npmPrefix is not in your PATH. Add it with:"
Write-Host " setx PATH `"$npmPrefix;%PATH%`""
Write-Host ''
if (-not $UserPrefix) {
$npmPrefix = (npm prefix -g 2>$null).Trim()
if ($npmPrefix) {
$pathEntries = $env:PATH -split ';' | Where-Object { $_ -ne '' }
if ($pathEntries -notcontains $npmPrefix) {
Write-Warn "$npmPrefix is not in your PATH. Add it with:"
Write-Host " setx PATH `"$npmPrefix;%PATH%`""
Write-Host ''
}
}
}
}

if ($UserPrefix) {
Write-Host ''
Write-Host "The CLI was installed to $UserPrefix."
Write-Host 'Add it to your PATH permanently with:'
Write-Host " setx PATH `"$UserPrefix;%PATH%`""
}

Write-Host ''
Write-Host 'Next step: configure your auth token with decodo setup'
Write-Host 'Get started:'
Write-Host ' decodo scrape https://ip.decodo.com'
Write-Host ' decodo search "decodo scraping api"'
Write-Host ' dcd whoami # shorthand alias'
Write-Host ' decodo whoami'
Write-Host ''
67 changes: 56 additions & 11 deletions docs/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ set -e

PACKAGE_NAME="@decodo/cli"
COMMAND_NAME="decodo"
COMMAND_ALIAS="dcd"
MIN_NODE_MAJOR=18

if [ -t 1 ]; then
Expand Down Expand Up @@ -49,6 +48,47 @@ Update Node.js from https://nodejs.org/ and try again."
echo "$version"
}

can_write_global() {
prefix=$(npm prefix -g 2>/dev/null) || return 1
[ -n "$prefix" ] || return 1

for dir in "${prefix}/lib/node_modules" "${prefix}/bin"; do
target="$dir"
while [ ! -d "$target" ]; do
target=$(dirname "$target")
done
[ -w "$target" ] || return 1
done
}

install_package() {
USER_PREFIX_BIN=""

if can_write_global; then
info "Installing ${PACKAGE_NAME} globally..."
if npm install -g "${PACKAGE_NAME}"; then
return
fi
warn "Global install failed. Falling back to a user-level install."
else
warn "No write permission for the npm global directory ($(npm prefix -g 2>/dev/null))."
info "Installing ${PACKAGE_NAME} to ${HOME}/.npm-global instead (no sudo needed)..."
fi

user_prefix="${HOME}/.npm-global"
mkdir -p "$user_prefix"

if ! npm install -g --prefix "$user_prefix" "${PACKAGE_NAME}"; then
error "Installation failed.
Try fixing your npm permissions (https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally)
or run the CLI without installing: npx ${PACKAGE_NAME} --help"
fi

USER_PREFIX_BIN="${user_prefix}/bin"
PATH="${USER_PREFIX_BIN}:${PATH}"
export PATH
}

main() {
printf "\n${BOLD}Decodo CLI Installer${RESET}\n\n"

Expand All @@ -60,29 +100,34 @@ main() {
error "npm is not available. Install npm and try again."
fi

info "Installing ${PACKAGE_NAME} globally..."
npm install -g "${PACKAGE_NAME}"
install_package

if command -v "$COMMAND_NAME" >/dev/null 2>&1; then
installed_version=$("$COMMAND_NAME" --version 2>/dev/null || echo "unknown")
printf "\n${GREEN}${BOLD}Success!${RESET} ${PACKAGE_NAME} ${installed_version} is installed.\n"
elif command -v "$COMMAND_ALIAS" >/dev/null 2>&1; then
installed_version=$("$COMMAND_ALIAS" --version 2>/dev/null || echo "unknown")
printf "\n${GREEN}${BOLD}Success!${RESET} ${PACKAGE_NAME} ${installed_version} is installed.\n"
else
printf "\n${GREEN}${BOLD}Installed!${RESET} You may need to restart your shell or add the npm global bin directory to your PATH.\n"
npm_bin=$(npm bin -g 2>/dev/null) || true
if [ -n "$npm_bin" ] && ! echo "$PATH" | tr ':' '\n' | grep -qx "$npm_bin"; then
warn "${npm_bin} is not in your PATH. Add it with:"
printf " export PATH=\"%s:\$PATH\"\n\n" "$npm_bin"
if [ -z "$USER_PREFIX_BIN" ]; then
npm_prefix=$(npm config get prefix 2>/dev/null) || true
npm_bin="${npm_prefix:+$npm_prefix/bin}"
if [ -n "$npm_bin" ] && ! echo "$PATH" | tr ':' '\n' | grep -qx "$npm_bin"; then
warn "${npm_bin} is not in your PATH. Add it with:"
printf " export PATH=\"%s:\$PATH\"\n\n" "$npm_bin"
fi
fi
fi

if [ -n "$USER_PREFIX_BIN" ]; then
printf "\nThe CLI was installed to ${BOLD}%s${RESET}.\n" "$USER_PREFIX_BIN"
printf "Add it to your PATH permanently by appending this line to your shell profile (e.g. ~/.zshrc or ~/.bashrc):\n"
printf " ${BOLD}export PATH=\"%s:\$PATH\"${RESET}\n" "$USER_PREFIX_BIN"
fi

printf "\nNext step: configure your auth token with ${BOLD}decodo setup${RESET}\n"
printf "Get started:\n"
printf " ${BOLD}decodo scrape${RESET} https://ip.decodo.com\n"
printf " ${BOLD}decodo search${RESET} \"decodo scraping api\"\n"
printf " ${BOLD}dcd whoami${RESET} # shorthand alias\n\n"
printf " ${BOLD}decodo whoami${RESET}\n\n"
}

main
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@decodo/cli",
"version": "0.1.3",
"version": "0.1.4",
"description": "Official CLI for the Decodo APIs",
"license": "MIT",
"type": "module",
Expand Down
80 changes: 40 additions & 40 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading