1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 06:37:46 +00:00

Add jc wrapper (#883)

This PR adds `jc` wrapper, so that `jc` output is automatically parsed
into a nushell data structure and you don't have to use `| from json`
filter to parse it.

References: https://kellyjonbrazil.github.io/jc/#jc
This commit is contained in:
Bruce Weirdan 2024-06-22 19:41:11 +02:00 committed by GitHub
parent 92db3a88eb
commit a992f5b4fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 71 additions and 0 deletions

30
modules/jc/mod.nu Normal file
View file

@ -0,0 +1,30 @@
# Run `jc` (Json Converter)
#
# This module provides a wrapper around the `jc` command line tool and automatically
# parses its output into a structured data format.
#
# Dependencies:
# * `jc`
#
# Installation:
# 1. Install the `jc` command line: https://kellyjonbrazil.github.io/jc/#installation
# 2. Import this module in your `config.nu`: `import ~/.local/share/nu_scripts/modules/jc/`
export def --wrapped main [...args]: [any -> table, any -> record, any -> string] {
let run = (^jc ...$args | complete)
if $run.exit_code != 0 {
error make {
msg: $run.stderr,
label: {
text: "jc execution failed",
span: (metadata $args).span
}
}
}
if '--help' in $args or '-h' in $args {
$run.stdout
} else {
$run.stdout | from json
}
}