itch

Crates.ioitch
lib.rsitch
version0.2.2
sourcesrc
created_at2021-04-10 22:35:57.346104
updated_at2024-10-04 16:52:13.573776
descriptionA cli tool for InTerCHanging between different serialized data formats
homepagehttps://github.com/FreddieGilbraith/itch
repositoryhttps://github.com/FreddieGilbraith/itch
max_upload_size
id381817
size32,757
Freddie Gilbraith (FreddieGilbraith)

documentation

https://github.com/FreddieGilbraith/itch

README

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.

Commit count: 7

cargo fmt