3 unstable releases

0.2.1 Nov 25, 2022
0.2.0 Nov 2, 2022
0.1.0 Apr 10, 2021

#1356 in Encoding

47 downloads per month

MIT license

14KB
211 lines

Itch

InTerCHanges one data format into another (get it?)

A very simple cli to convert between some of the most common plain-text data formats. It can't perform every conversion that might be theoretically possible, but it tries its best

Installation

itch currently does not offer binary downloads, and must instead be built from source. You can use rustup to get the rust toolchain, the run the following command to download and install itch:

cargo install --force --git https://github.com/FreddieRidell/itch.git

Overview

USAGE:
    itch [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -f, --from <from-type>    Format of the input, will be derived if possible
    -i, --input <input>       Path to the input file, leave empty for stdin
    -o, --output <output>     Path to the output file, leave empty for stdout
    -t, --to <to-type>        Format of the output, will be derived if possible

itch can take input from a file or std in, and output to a file or std out. If given a file as input or output it will try to detect the format automatically. itch doesn't do any manipulation to data to satisfy the different constructs that different formats can express; so there's no guarantee that a conversion will work.

Formats

First Class

Can all be pretty reliably used as sources and targets

  • json
  • toml
  • yaml

Second Class

Somewhat unreliable, but can be used for basic transformations

  • url query strings
  • xml

Behaviour

itch should always produce the same output when given the same input:

input

echo '<element key="value"><child/></element>'
   | itch -f xml -t json

output

{ "key": "value", "child": {} }

itch will not necessarily produce output that can automatically be reversed:

input

echo '<element key="value"><child/></element>'
   | itch -f xml -t json
   | itch -f json -t xml

output

<key>value</key><child></child>

Implementation

Uses serde and it's own internal data representation format to act as an intermediary between the different data formats:

enum Itch {
    Obj(IndexMap<String, Itch>),
    Array(Vec<Itch>),
    Bool(bool),
    Int(i64),
    Float(f64),
    Text(String),
}

Each deserialization step converts to this type, and each serialisation step converts from it.

Dependencies

~4.5MB
~91K SLoC