diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 23b161b..68c9709 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -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 @@ -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 diff --git a/Cargo.toml b/Cargo.toml index daabfa8..949e325 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,6 @@ [package] name = "nuq" +description = "A multi-format frontend to jq" version = "0.1.0" edition = "2021" authors = ["Erik Schubert "] diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..64081f3 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,28 @@ +# Maintainer: Erik "Nuckal777" Schubert +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" +} diff --git a/README.md b/README.md index e04fef4..f5af6f1 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 ``` @@ -26,15 +26,19 @@ Arguments: Options: -i, --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, 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 + 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. diff --git a/release-notes/v0.1.0.md b/release-notes/v0.1.0.md new file mode 100644 index 0000000..f8a032f --- /dev/null +++ b/release-notes/v0.1.0.md @@ -0,0 +1 @@ +Initial release diff --git a/src/lib.rs b/src/lib.rs index 95c70e0..2738b44 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -267,7 +267,7 @@ impl Args { fn make_inputs(&self) -> anyhow::Result> { 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, }]); @@ -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, }] @@ -559,12 +559,12 @@ mod test { #[test] fn slurp() -> Result<(), Box> { 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), }; @@ -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, }; diff --git a/tests/cli.rs b/tests/cli.rs index 4a86f6c..c7606ac 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -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) {