Skip to content

Commit

Permalink
Release v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuckal777 committed Nov 14, 2022
1 parent 1d734b1 commit ca555a0
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
required: true
env:
TARGET_VERSION: ${{ github.event.inputs.version }}
JQ_LIB_DIR: /usr/lib/x86_64-linux-gnu
jobs:
release:
name: Create release
Expand All @@ -23,6 +24,10 @@ jobs:
else
exit 1
fi
- name: Install libjq-dev and libonig-dev
run: |
sudo apt-get update
sudo apt-get install libjq-dev libonig-dev
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[package]
name = "nuq"
description = "A multi-format frontend to jq"
version = "0.1.0"
edition = "2021"
authors = ["Erik Schubert <[email protected]>"]
Expand Down
28 changes: 28 additions & 0 deletions PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Maintainer: Erik "Nuckal777" Schubert <[email protected]>
pkgname=nuq
pkgver=0.1.0
pkgrel=1
pkgdesc="A multi-format frontend to jq"
arch=('x86_64')
url="https://github.com/Nuckal777/nuq"
license=('Unlicense')
depends=('gcc-libs' 'jq')
makedepends=('cargo' 'git')
source=("$pkgname"::"git+https://github.com/Nuckal777/nuq#tag=v0.1.0")
noextract=()
md5sums=('SKIP')

check() {
cd "$pkgname"
JQ_LIB_DIR=/lib RUSTUP_TOOLCHAIN=stable cargo test --release --locked --target-dir=target
}

build() {
cd "$pkgname"
JQ_LIB_DIR=/lib RUSTUP_TOOLCHAIN=stable cargo build --release --locked --all-features --target-dir=target
}

package() {
cd "$pkgname"
install -Dm 755 target/release/${pkgname} -t "${pkgdir}/usr/bin"
}
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
![Build Status](https://img.shields.io/github/workflow/status/Nuckal777/nicator/test)
[![Coverage Status](https://coveralls.io/repos/github/Nuckal777/nuq/badge.svg?branch=master)](https://coveralls.io/github/Nuckal777/nuq?branch=master)

A multi-format frontend to jq.
A multi-format frontend to jq supporting pretty-printing and syntax highlighting. Whether you need to process JSON, YAML or TOML pipe it into `nuq` and be done with it.

## Motivation
Based on some recent discussion at work I decided that an other option to process YAML is required. :wink:
Expand All @@ -12,7 +12,7 @@ To my knowledge there are two common options for that:
- [yq](https://github.com/mikefarah/yq), which uses Golang and has its interpreter with differs from jq's interpreter.
- [yq](https://github.com/kislyuk/yq), which uses python to convert YAML to JSON and shells out to jq after. Therefore it is slower than native implementations.

`nuq` should have decent speed and can execute all programs accepted by jq due to calling libjq directly. To be fair `nuq` has to parse JSON input streams containing multiple documents to split them before they can be handed off to libjq, so a straight `jq` should be faster. :poop:
`nuq` should have decent speed and can execute all programs accepted by jq due to calling libjq directly. To be fair `nuq` has to parse JSON input streams containing multiple documents to split them before they can be handed off to libjq, so a straight `jq` should be faster.

## Usage
```
Expand All @@ -26,15 +26,19 @@ Arguments:
Options:
-i, --input-format <INPUT_FORMAT>
Input format, will be guessed by extension if omitted [possible values: json, yaml, ron, toml]
Input format, will be guessed by extension or content [possible values: json, yaml, ron, toml]
-o, --output-format <OUTPUT_FORMAT>
Output format, if omitted will return whatever libjq produces. Toml output may require reordering the input [possible values: json, yaml, ron, toml]
Output format, if omitted will return the input format. Toml output may require reordering the input [possible values: json, yaml, ron, toml]
-r, --raw
If jq outputs a JSON string only output contained plain text. This post-processes the jq output, so it may not behave the same as "jq -r"
--slurp
Concatenate all input files into a JSON array before processing it with jq
-c, --color <COLOR>
Enables or disables colored output. By default coloring is enabled when writing to a tty [possible values: true, false]
-p, --pretty
Pretty-prints the out, if the serializer supports that
```

## How it works
Converts the input using [serde](https://serde.rs/) to JSON, runs it through `jq` with [jq-rs](https://crates.io/crates/jq-rs), which uses `libjq` (no shell-out) and transform it to the output format with [serde](https://serde.rs/) again.
Should techically work on all formats supported by [serde](https://serde.rs/).
Techically support for all formats supported by [serde](https://serde.rs/) can be implemented.
1 change: 1 addition & 0 deletions release-notes/v0.1.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Initial release
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl Args {
fn make_inputs(&self) -> anyhow::Result<Vec<Input>> {
if self.files.is_empty() {
return Ok(vec![Input {
ext: "".to_owned(),
ext: String::new(),
reader: Box::new(std::io::stdin()),
input_format: self.input_format,
}]);
Expand Down Expand Up @@ -377,7 +377,7 @@ pub fn run(args: &Args) -> anyhow::Result<()> {
let inputs = if args.slurp {
let array = slurp(&mut args.make_inputs()?)?;
vec![Input {
ext: "".to_owned(),
ext: String::new(),
reader: Box::new(Cursor::new(array)),
input_format: args.input_format,
}]
Expand Down Expand Up @@ -559,12 +559,12 @@ mod test {
#[test]
fn slurp() -> Result<(), Box<dyn Error>> {
let json = Input {
ext: "".to_owned(),
ext: String::new(),
reader: Box::new(Cursor::new(r#"{"a":"b"}"#)),
input_format: Some(FileFormat::Json),
};
let yaml = Input {
ext: "".to_owned(),
ext: String::new(),
reader: Box::new(Cursor::new("c: d")),
input_format: Some(FileFormat::Yaml),
};
Expand All @@ -576,13 +576,13 @@ mod test {
#[test]
fn guess() {
let mut json = Input {
ext: "".to_owned(),
ext: String::new(),
reader: Box::new(Cursor::new(r#"{"a":"b"}"#)),
input_format: None,
};
assert!(json.read_to_docs().is_ok());
let mut yaml = Input {
ext: "".to_owned(),
ext: String::new(),
reader: Box::new(Cursor::new("c: d")),
input_format: None,
};
Expand Down
2 changes: 1 addition & 1 deletion tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn slurp() {
fn yaml_stdin_identity_color() {
let (exit, output) = spawn_nuq(&["-i", "yaml", "-c", "true", "."], b"key: test");
assert!(exit.success());
assert_eq!(output, "\u{1b}[38;2;99;163;92mkey\u{1b}[38;2;50;50;50m:\u{1b}[38;2;50;50;50m \u{1b}[38;2;24;54;145mtest\u{1b}[38;2;50;50;50m\n\u{1b}[0m");
assert_eq!(output, "\u{1b}[38;2;191;97;106mkey\u{1b}[38;2;192;197;206m:\u{1b}[38;2;192;197;206m \u{1b}[38;2;163;190;140mtest\u{1b}[38;2;192;197;206m\n\u{1b}[0m");
}

fn spawn_nuq(args: &[&str], input: &[u8]) -> (ExitStatus, String) {
Expand Down

0 comments on commit ca555a0

Please sign in to comment.