toq

Crates.iotoq
lib.rstoq
version0.1.0
sourcesrc
created_at2024-02-11 10:26:56.636965
updated_at2024-02-11 10:26:56.636965
descriptionA small binary that allows for quick parsing of toml files
homepage
repositoryhttps://gitlab.com/mxcr_cpu/aq
max_upload_size
id1135761
size15,914
Maximus Cisneros (MXCR-cpu)

documentation

README

toq

Gettings what you need, when you need it from toml files

I created this small binary when I found that there really weren't any alternatives to jq when it came to working with toml files that didn't rely on an intermediary json file step, so I created one.

Installation

Download the binary from crates.io

cargo install toq

Usage

The design of the binary was replicated off of jq. Althougth not all of jq's features were implemented, the binary still provides functionality when attempting to get information from toml files rapidly.

For example, here is our toml file:

# test.toml

[[sources]]
name = "Some Name"
date = "Some date"

[[sources.times]]
time_1 = "1010010"
time_2 = "1010101"

[[sources.times]]
time_3 = "1111111"
time_4 = "0000000"


[[sources]]
name = "Other Name"
date = "Other date"

[[sources.times]]
time_1 = "202020"
time_2 = "20202020"

[[sources.times]]
time_3 = "222222"
time_4 = "00000000"

[[sources]]
name = "Other Other Name"
date = "Other Other date"

[[sources.times]]
time_1 = "30303030"
time_2 = "303030300"

[[sources.times]]
time_3 = "33333333"
time_4 = "000000000"

Running a simple query, we get:

$ toq '.' "test.toml"
{ sources = [{ date = "Some date", name = "Some Name", times = [{ time_1 = "1010010", time_2 = "1010101" }, { time_3 = "1111111", time_4 = "0000000" }] }, { date = "Other date", name = "Other Name", times = [{ time_1 = "202020", time_2 = "20202020" }, { time_3 = "222222", time_4 = "00000000" }] }, { date = "Other Other date", name = "Other Other Name", times = [{ time_1 = "30303030", time_2 = "303030300" }, { time_3 = "33333333", time_4 = "000000000" }] }] }

Probing further:

$ toq '.sources' "test.toml"
[{ date = "Some date", name = "Some Name", times = [{ time_1 = "1010010", time_2 = "1010101" }, { time_3 = "1111111", time_4 = "0000000" }] }, { date = "Other date", name = "Other Name", times = [{ time_1 = "202020", time_2 = "20202020" }, { time_3 = "222222", time_4 = "00000000" }] }, { date = "Other Other date", name = "Other Other Name", times = [{ time_1 = "30303030", time_2 = "303030300" }, { time_3 = "33333333", time_4 = "000000000" }] }]

Indexing over arrays:

$ toq '.sources[]' "test.toml"
{ date = "Some date", name = "Some Name", times = [{ time_1 = "1010010", time_2 = "1010101" }, { time_3 = "1111111", time_4 = "0000000" }] }
{ date = "Other date", name = "Other Name", times = [{ time_1 = "202020", time_2 = "20202020" }, { time_3 = "222222", time_4 = "00000000" }] }
{ date = "Other Other date", name = "Other Other Name", times = [{ time_1 = "30303030", time_2 = "303030300" }, { time_3 = "33333333", time_4 = "000000000" }] }

Traversing over nested arrays:

$ toq '.sources[].times[]' "test.toml"
{ time_1 = "1010010", time_2 = "1010101" }
{ time_3 = "1111111", time_4 = "0000000" }
{ time_1 = "202020", time_2 = "20202020" }
{ time_3 = "222222", time_4 = "00000000" }
{ time_1 = "30303030", time_2 = "303030300" }
{ time_3 = "33333333", time_4 = "000000000" }

Selecting for an entry within the nested arrays will filter through the only objects that possess those entries:

$ toq '.sources[].times[].time_1' "test.toml"
"1010010"
"202020"
"30303030"

As you can see, there is some potential in combining this binary with other CLI tools to expedite text processing for this file type when you need it.

Commit count: 0

cargo fmt