ocpi-tariffs-cli 0.53.0

CLI application for OCPI tariff calculation
Documentation

# OCPI tariffs CLI

This crate provides a binary for doing calculations with
[OCPI](https://evroaming.org/ocpi-background/)
[tariffs](https://github.com/ocpi/ocpi/blob/2.2.1/mod_tariffs.asciidoc#1-tariffs-module).
Specifically for the [`OCPI 2.2.1`](https://evroaming.org/app/uploads/2021/11/OCPI-2.2.1.pdf) and
[`OCPI 2.1.1`](https://github.com/ocpi/ocpi/releases/download/2.1.1-d2/OCPI_2.1.1-d2.pdf) version.

## Installation

First install [Rust](https://www.rust-lang.org/tools/install) and then install
the OCPI tariffs command line tool:

```text
cargo install ocpi-tariffs-cli
```

## Usage

The binary is executed as `ocpi-tariffs`. Every subcommand takes
`-o, --ocpi-version`, which is required and accepts `v221` or `v211`.
`guess-version` is the exception, since working out the version is its job.

Every subcommand reads its JSON from the path given by `-f, --file` (`-c, --cdr` for `price`),
and from standard input when that path is omitted, so the tool composes in a pipeline.

Run `ocpi-tariffs --help` for the list of subcommands, or `ocpi-tariffs <subcommand> --help`
for the options of one.

### Subcommands

#### `price`

Price a charge detail record (CDR) against a tariff and print a breakdown of the calculated costs,
period by period, alongside the totals the CDR itself carries so the two can be compared.

The tariff comes from `-t, --tariff` if given. Otherwise it is taken from the CDR, which may
embed several, in which case the first valid one is used. A tariff is valid for a session when
it starts before the session does and ends after the session starts.

Local times in a tariff are evaluated in the zone given by `-z, --timezone`. If you omit the
tariff the timezone is found or inferred from the CDR.

```text
ocpi-tariffs price --ocpi-version v221 --cdr cdr.json --tariff tariff.json
```

#### `explain`

Describe in human language what a tariff charges and under which conditions. The explanation
goes to standard output so it can be piped or redirected; status messages and warnings go to
standard error.

`-l, --language` selects the language: `en-US` for English or `nl-NL` for Dutch. `--pretty`
prints the source tariff JSON before the explanation.

```text
ocpi-tariffs explain --ocpi-version v221 --language nl-NL --file tariff.json
```

#### `lint`

Report the problems a tariff can have while still being valid against the OCPI schema: a
restriction that can never match, a price bound the wrong way round, a `day_of_week` list
covering the whole week. `--pretty` prints the tariff JSON alongside the warnings.

```text
ocpi-tariffs lint --ocpi-version v221 --file tariff.json
```

#### `guess-version`

Work out whether a JSON document is OCPI 2.1.1 or 2.2.1. Takes `-t, --type` with `cdr` or
`tariff` to say which kind of object it is, and takes no `--ocpi-version`. Pass `--validate` to
also check the document's fields against the spec for the version it settles on.

```text
ocpi-tariffs guess-version --type cdr --file cdr.json --validate
```