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:

  1. Load your configuration file
  2. Validate the configuration
  3. Connect to the payment provider(s) using environment variables
  4. Synchronize products and prices
  5. 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:

This is perfect for:

Verbose Mode

Use the --verbose flag to get detailed information about the synchronization process:

npx prices-as-code config.ts --verbose

This will show:

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:

Next Steps