#nushell-plugin #dhall #nu #parse #support #add

bin+lib nu_plugin_from_dhall

Nushell plugin to add Dhall support

1 unstable release

0.0.1 Jun 18, 2021

#5 in #dhall

MIT and maybe CC-PDDC

17KB
123 lines

nu_plugin_from_dhall

Check Test

This is a plugin for Nushell to open Dhall files into nu's structured data types.

Installing

cargo install nu_plugin_from_dhall

Usage

Given a Dhall file:

> cat example.dhall
let AccountType = < Guest | User | Admin >

let Person =
      { name : Text
      , age : Natural
      , accountType : AccountType
      , nickname : Optional Text
      }

let alice
    : Person
    = { name = "Alice"
      , age = 24
      , accountType = AccountType.Admin
      , nickname = Some "Cool Alice"
      }

let bob
    : Person
    = { name = "Bob"
      , age = 49
      , accountType = AccountType.User
      , nickname = None Text
      }

let carlo
    : Person
    = { name = "Carlo"
      , age = 20
      , accountType = AccountType.Guest
      , nickname = Some "Cooler Carlo"
      }

in  [ alice, bob, carlo ]

Use open to parse the Dhall expression into structured data that Nushell can pipe:

> open example.dhall
───┬─────────────┬─────┬───────┬──────────────
 # │ accountType │ age │ name  │   nickname
───┼─────────────┼─────┼───────┼──────────────
 0 │ [row Admin] │  24 │ Alice │ Cool Alice
 1 │ [row User]  │  49 │ Bob   │
 2 │ [row Guest] │  20 │ Carlo │ Cooler Carlo
───┴─────────────┴─────┴───────┴──────────────

> open example.dhall | where age > 20 | get name
───┬───────
 0 │ Alice
 1 │ Bob
───┴───────

Dependencies

~22–57MB
~1M SLoC