tinyactors fmt

Rewrite charts and system manifests in the canonical layout.

Usage

shell
tinyactors fmt [options] FILE...

Writes each chart or system manifest in one canonical layout. It indents two spaces per element level and writes one element, comment or processing instruction per line. Attributes stay in the order written. Only the whitespace between elements changes: comments stay where they are and attribute values as written. Script, data, content and assign elements keep their content byte for byte. So do elements of other namespaces and mixed content. Each file's canonical text must compile to the image its original gives, lines and columns aside, or the file is refused. One file goes to standard output. -w rewrites the files in place, each whole or not at all. --check writes nothing. With -w or --check the answer lists the files and whether each changed.

Options

  • -w, --writeRewrite each file in place, whole or not at all.
  • -I, --include DIRSearch DIR for a src that is not beside the file naming it, in the order given. Repeatable.
  • --checkWrite nothing, and exit with 1 when a file is not in canonical form.

Configure output formats like -f json using the shared options on the command reference.

Examples

shell
tinyactors fmt order.scxml
output
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" name="order" datamodel="ecmascript" initial="open">
  <datamodel>
    <data id="total" expr="0"/>
    <data id="attempts" expr="0"/>
    <data id="charge" expr="null"/>
  </datamodel>
  <state id="open">
    <transition event="item.added" cond="_event.data.price &gt; 0">
      <assign location="total" expr="total + _event.data.price"/>
    </transition>
    <transition event="checkout" cond="total &gt; 0" target="paying"/>
    <transition event="cancel" target="cancelled"/>
  </state>
  <state id="paying">
    <onentry>
      <assign location="attempts" expr="attempts + 1"/>
      <send type="payments" target="charges" event="charge" id="pay">
        <param name="amount" expr="total"/>
      </send>
      <send event="payment.timeout" delay="30s" id="deadline"/>
    </onentry>
    <onexit>
      <cancel sendid="deadline"/>
    </onexit>
    <transition event="charge.ok" target="paid">
      <assign location="charge" expr="_event.data.charge"/>
    </transition>
    <transition event="charge.declined error.communication payment.timeout" cond="attempts &lt; 3" target="paying"/>
    <transition event="charge.declined error.communication payment.timeout" target="cancelled"/>
  </state>
  <state id="paid">
    <transition event="shipped" target="shipped"/>
  </state>
  <final id="shipped">
    <donedata>
      <param name="charge" expr="charge"/>
    </donedata>
  </final>
  <final id="cancelled"/>
</scxml>

Write a chart's canonical text to standard output.

shell
tinyactors fmt -w charts/*.scxml system.xml
output
# Fmt

- **Mode**: write
- **Files**: 3
- **Changed**: 0
- **Refused**: 0

## Results

| File | Changed | Refused | Image |
| --- | --- | --- | --- |
| charts/order.scxml | no | no | same |
| charts/payment.scxml | no | no | same |
| system.xml | no | no | same |

## Diagnostics

_none_

Rewrite charts and a system manifest in place.

shell
tinyactors fmt --check charts/*.scxml
output
# Fmt

- **Mode**: check
- **Files**: 2
- **Changed**: 0
- **Refused**: 0

## Results

| File | Changed | Refused | Image |
| --- | --- | --- | --- |
| charts/order.scxml | no | no | same |
| charts/payment.scxml | no | no | same |

## Diagnostics

_none_

Fail if a chart is not in canonical form.

shell
tinyactors fmt --check -f json -I shared order.scxml
output
{
  "mode": "check",
  "files": 1,
  "changed": 0,
  "refused": 0,
  "results": [
    {
      "file": "order.scxml",
      "changed": false,
      "refused": false,
      "image": "same"
    }
  ],
  "diagnostics": []
}

Check a chart that includes files from shared, in JSON.

Exit status

  • 1A file is refused: it is no XML fmt can rewrite, or its canonical text gives another image.
  • 1With --check, a file is not in canonical form.
  • 3A file cannot be read or written, or memory runs out.

Related pages