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.

Commands

The CLI supports several commands:

Command Description Example
sync (default) Synchronize your pricing schema with provider npx prices-as-code config.yml
pull Pull pricing from provider into a local config file npx prices-as-code pull config.yml
generate Generate a template pricing structure npx prices-as-code generate config.yml

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=<path> Specify custom .env file location npx prices-as-code config.ts --env=./configs/.env.production
--verbose Show detailed logs of the synchronization process npx prices-as-code config.ts --verbose
--format=<format> Output format for pull and generate commands (yaml, json, ts) npx prices-as-code pull --format=ts config.ts
--stripe-key=<key> Stripe API key (overrides env var) npx prices-as-code config.ts --stripe-key=sk_test_123
--write-back Write provider IDs back to your config file npx prices-as-code config.ts --write-back
--help Show help information npx prices-as-code --help
--version Show version information npx prices-as-code --version

Generate Command Options

The generate command supports additional options to customize the template:

Option Description Example
--tiers=<tiers> Comma-separated list of product tiers --tiers=free,basic,pro
--currency=<cur> ISO currency code --currency=eur
--intervals=<int> Comma-separated list of intervals --intervals=month,year
--no-metadata Don't include metadata in generated file --no-metadata
--no-features Don't include feature lists in generated products --no-features

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