Skip to content

Command Line Interface

Spark-ID provides a powerful command-line interface for generating and validating IDs directly from your terminal.

Overview

The spark-id CLI tool allows you to:

  • ✅ Generate single or multiple IDs
  • ✅ Add prefixes to generated IDs
  • ✅ Validate existing IDs
  • ✅ Parse and display ID components
  • ✅ Use in scripts and automation
  • ✅ Pipe output to other commands

Quick Start

bash
# Generate a single ID
spark-id

# Generate with prefix
spark-id -p USER

# Generate multiple IDs
spark-id -c 5

# Validate an ID
spark-id -v USER_YBNDRFG8EJKMCPQXOT1UWISZA345H769

Installation

Global Installation

bash
npm install -g @aexoo-ai/spark-id

Using npx (No Installation Required)

bash
npx @aexoo-ai/spark-id

Local Installation

bash
npm install @aexoo-ai/spark-id
npx spark-id

pnpm Workspace Usage

bash
# Add to package.json scripts
pnpm spark-id

# Or use npx (recommended for workspaces)
npx @aexoo-ai/spark-id -p USER

Basic Usage

Generate IDs

bash
# Simple ID generation
spark-id
# Output: YBNDRFG8EJKMCPQXOT1UWISZA345H769

# With prefix
spark-id -p USER
# Output: USER_YBNDRFG8EJKMCPQXOT1UWISZA345H769

# Multiple IDs
spark-id -c 3
# Output:
# YBNDRFG8EJKMCPQXOT1UWISZA345H769
# abc123def456ghi789
# xyz789uvw012mno345

Validation

bash
# Validate a single ID
spark-id -v USER_YBNDRFG8EJKMCPQXOT1UWISZA345H769
# Output: true

# Validate invalid ID
spark-id -v invalid-id
# Output: false

Parsing

bash
# Parse an ID to see its components
spark-id --parse USER_YBNDRFG8EJKMCPQXOT1UWISZA345H769
# Output:
# {
#   "prefix": "USER",
#   "id": "YBNDRFG8EJKMCPQXOT1UWISZA345H769",
#   "full": "USER_YBNDRFG8EJKMCPQXOT1UWISZA345H769"
# }

Advanced Usage

Scripting and Automation

bash
# Generate IDs for a script
for i in {1..10}; do
  echo "ID $i: $(spark-id -p USER)"
done

# Use in shell scripts
USER_ID=$(spark-id -p USER)
echo "Created user with ID: $USER_ID"

# Pipe to other commands
spark-id -c 100 | grep "USER_" | head -10

Batch Operations

bash
# Generate IDs for different entity types
spark-id -p USER -c 5
spark-id -p TXN -c 10
spark-id -p ORDER -c 3

# Validate multiple IDs from a file
cat ids.txt | xargs -I {} spark-id -v {}

Integration with Other Tools

bash
# Use with jq for JSON processing
spark-id --parse USER_YBNDRFG8EJKMCPQXOT1UWISZA345H769 | jq '.prefix'

# Use with sed for text processing
spark-id -c 5 | sed 's/^/ID: /'

# Use with awk for data analysis
spark-id -p USER -c 100 | awk '{print length($0)}'

Output Formats

Default Output

bash
spark-id
# YBNDRFG8EJKMCPQXOT1UWISZA345H769

JSON Output

bash
spark-id -f json
# "YBNDRFG8EJKMCPQXOT1UWISZA345H769"

spark-id -p USER -f json
# "USER_YBNDRFG8EJKMCPQXOT1UWISZA345H769"

CSV Output

bash
spark-id -c 5 -f csv
# YBNDRFG8EJKMCPQXOT1UWISZA345H769,abc123def456ghi789,xyz789uvw012mno345,pqr123stu456vwx789,def456ghi789jkl012

Error Handling

Invalid Arguments

bash
spark-id --invalid-flag
# Error: Unknown option: --invalid-flag
# Usage: spark-id [options]

spark-id -c -5
# Error: Count must be a positive integer

Invalid IDs

bash
spark-id -v invalid-id
# false

spark-id --parse invalid-id
# Error: Invalid ID format: invalid-id

Exit Codes

  • 0: Success
  • 1: Error or validation failed

Troubleshooting

"spark-id command not found"

This is common in pnpm workspaces or when the binary isn't in your PATH. Try these solutions:

bash
npx @aexoo-ai/spark-id -p USER -c 5

Add to package.json scripts

json
{
  "scripts": {
    "spark-id": "spark-id"
  }
}

Then run: pnpm spark-id

Use direct binary path

bash
# When installed as a package
./node_modules/.bin/spark-id -p USER

# In development
node dist/cli.cjs -p USER

Install globally

bash
npm install -g @aexoo-ai/spark-id
# or
pnpm add -g @aexoo-ai/spark-id

Performance

Generation Speed

bash
# Test generation speed
time spark-id -c 1000 > /dev/null
# real    0m0.123s
# user    0m0.098s
# sys     0m0.025s

Memory Usage

The CLI is optimized for minimal memory usage:

bash
# Monitor memory usage
/usr/bin/time -v spark-id -c 10000 > /dev/null
# Maximum resident set size (kbytes): 2048

Examples

Development Workflow

bash
# Generate test data
echo "Test Users:" > test-data.txt
spark-id -p USER -c 10 >> test-data.txt
echo "Test Transactions:" >> test-data.txt
spark-id -p TXN -c 20 >> test-data.txt

Database Seeding

bash
# Generate SQL insert statements
spark-id -p USER -c 5 | awk '{print "INSERT INTO users (id) VALUES ('\''" $0 "'\'');"}'

API Testing

bash
# Generate test IDs for API calls
curl -X GET "http://api.example.com/users/$(spark-id -p USER)"

Released under the MIT License.