cim-kit 0.6.0

IEC CIM/CGMES for power systems: CIM/XML I/O that reproduces the file set, profile-aware validation, typed RDF export
Documentation
+++
title = "Command line"
description = "The cim command: inspect, validate, export, convert to RDF and diff CGMES model sets from a shell. Full option reference and exit codes."
weight = 70
+++

`cim` is a thin shell over the public API: seven subcommands over a model set given as
files, archives or directories.

```bash
cargo install cim-kit --features cli
brew install hupe1980/tap/cim-kit    # macOS (Apple Silicon) and Linux
```

## Commands

| Command | Does |
|---|---|
| `cim info <input>…` | What a model set contains: files, object counts, profile coverage, findings |
| `cim validate <input>…` | Structural checks; exits 1 on any error |
| `cim export <input>… --out DIR` | Write the model back as CIM/XML |
| `cim rdf <input>… --out DIR` | Export as RDF, one graph per profile with data |
| `cim diff <base> <target>` | Compute a `dm:DifferenceModel` |
| `cim apply <input>… --change F --out DIR` | Apply a change set and write the result |
| `cim schema` | What the built-in vintages declare |

An `<input>` is a CIM/XML file, a zip archive, or a directory holding either. Several are
loaded into **one** model.

## Options

| Option | Effect |
|---|---|
| `-o`, `--out PATH` | Where to write — a directory, or a file for `diff` |
| `--vintage KEY` | Which schema to read against (`cgmes3`, `cgmes2`); by default it is detected from the input |
| `--profile KEY` | Restrict `rdf` and `diff` to a profile, e.g. `SSH`; repeat it for a file that serves several — `--profile EQ --profile OP --profile SC` writes the one graph a CGMES 2.4.15 Equipment file contains |
| `--change FILE` | A `dm:DifferenceModel` for `apply`; repeat to apply several, in the order given |
| `--assume-profile KEY` | Which profile a file's values belong to when it declares none — a document with no `md:FullModel` |
| `--rule CODE` | Show only this rule in `validate`, e.g. `CIM0007` |
| `--ntriples` | Write N-Triples rather than Turtle |
| `--merged` | `rdf` writes one graph for the whole model, not one per profile |
| `--strict` | Fail on anything the schema does not define |
| `--single-description` | Report an object described more than once in one file (`CIM0005`) |
| `--max-input SIZE` | Stop reading after `SIZE` bytes, archives counted decompressed (default `8GiB`; `512MB`, `16GiB`, `unlimited`) |
| `--limit N` | How many findings to list (default 20; `0` for all) |
| `-q`, `--quiet` | Less chatter |
| `-h`, `--help` | Usage |
| `-V`, `--version` | Which release this binary is |

## Exit status

| | |
|---|---|
| `0` | Clean |
| `1` | The model has errors |
| `2` | The command was wrong, or could not do its job — including an input over `--max-input` |

An input over the budget writes nothing and says what to try:

```text
cim: input exceeds the 8GiB input budget (8GiB read while reading EQ.xml); rerun with --max-input 32GiB, or --max-input unlimited
```

`cim validate` works directly as a CI gate:

```bash
cim validate model/ --rule CIM0007 || exit 1
```

## Examples

```text
$ cim info MicroGrid-Type1-NL-MAS/
== files ==
  20210323T1730Z_1D_NL_EQ_1.xml     EQ+SC   2021-03-23T17:30:00Z
  20210323T1730Z_1D_NL_SSH_1.xml    SSH     2021-03-23T17:30:00Z
  …

== model ==
  objects              602
  values               3632
  Substation           1
  ACLineSegment        5
  PowerTransformer     3

== profile coverage ==
  EQ          247 objects       1577 values
  SSH         114 objects        189 values
  SV           86 objects        213 values

== diagnostics ==
  CIM0006       51
  CIM0014        1
```

```bash
# Either vintage, detected from the document.
cim info CGMES_v2.4.15_MicroGridTestConfiguration_T4_BE_BB_Complete_v2.zip
cim info model/ --vintage cgmes2    # forced; a mismatch is CIM0021 and exits 1

# Compute a change set, then apply it to the model it was computed against.
cim diff before/ after/ --out change_DIFF.xml
cim apply before/ --change change_DIFF.xml --out updated/

# Typed RDF for a SHACL engine or a triple store.
cim rdf model/ --out graphs/ --ntriples
```

## Output streams

- `cim diff` without `--out` writes the document alone to stdout and the summary to stderr,
  so `cim diff a b > change_DIFF.xml` yields a file. With `--out`, the summary goes to stdout.
- `cim rdf` writes the paths it wrote to stdout and the profiles it skipped for lack of data
  to stderr.
- A closed pipe (`cim info big-model/ | head`) ends the command cleanly.