Command-Line Interface
Prices as Code provides a powerful command-line interface (CLI) that makes it easy to synchronize your pricing configuration with supported payment providers. This guide covers all the CLI features and options.
Basic Usage
The simplest way to use the CLI is to provide the path to your configuration file:
npx prices-as-code path/to/config.ts
Or for YAML files:
npx prices-as-code path/to/config.yml
This will:
- Load your configuration file
- Validate the configuration
- Connect to the payment provider(s) using environment variables
- Synchronize products and prices
- Report the results
Installing the CLI
If you use the CLI frequently, you might want to install it globally:
npm install -g prices-as-code
Then you can use it without npx:
prices-as-code path/to/config.ts
CLI Options
Option | Description | Example |
---|---|---|
--dry-run |
Simulate synchronization without making actual changes | npx prices-as-code config.ts --dry-run |
--env-file |
Specify custom .env file location | npx prices-as-code config.ts --env-file ./configs/.env.production |
--verbose |
Show detailed logs of the synchronization process | npx prices-as-code config.ts --verbose |
--provider |
Specify a provider (useful when config has multiple providers) | npx prices-as-code config.ts --provider stripe |
--help |
Show help information | npx prices-as-code --help |
--version |
Show version information | npx prices-as-code --version |
Environment Variables
The CLI looks for provider API keys in environment variables. You can set these in a .env
file in your project root or provide them directly in your environment.
Supported Environment Variables
Provider | Environment Variable |
---|---|
Stripe | STRIPE_SECRET_KEY |
Recurly | RECURLY_API_KEY |
Example .env File
# .env file
STRIPE_SECRET_KEY=sk_test_your_stripe_key
RECURLY_API_KEY=your_recurly_key
Using the Dry Run Mode
The --dry-run
flag is particularly useful for testing your configuration before applying changes to your production environment:
npx prices-as-code config.ts --dry-run
In dry run mode, the CLI will:
- Validate your configuration
- Connect to your provider(s)
- Report what changes would be made (creates, updates, deletes)
- Not make any actual changes to your provider accounts
This is perfect for:
- Verifying your configuration is correct
- Checking what would change before committing
- Testing CI/CD pipelines
Verbose Mode
Use the --verbose
flag to get detailed information about the synchronization process:
npx prices-as-code config.ts --verbose
This will show:
- Configuration validation details
- API calls to the provider
- Detailed information about each product and price being synchronized
- Any warnings or errors in detail
Handling Multiple Providers
If your configuration file includes products and prices for multiple providers, you can specify which provider to synchronize with:
npx prices-as-code config.ts --provider stripe
This is useful when:
- You want to update each provider separately
- You're testing integration with a new provider
- One provider is temporarily unavailable
Next Steps
- Learn about CI/CD Integration to automate your pricing updates
- Explore Custom Pricing Logic for complex scenarios
- Check out Working with Metadata for enhanced flexibility