dhall-1.41.2: A configuration language guaranteed to terminate

Safe Haskell | Safe-Inferred
Language | Haskell2010

Dhall.DirectoryTree

Contents

- Filesystem

Description

Implementation of the `dhall to-directory-tree` subcommand

Synopsis

- toDirectoryTree :: FilePath -> Expr Void Void -> IO ()
- newtype FilesystemError = FilesystemError {
  - unexpectedExpression :: Expr Void Void
  }

# Filesystem

toDirectoryTree :: FilePath -> Expr Void Void -> IO () Source #

Attempt to transform a Dhall record into a directory tree where:

- Records are translated into directories
- `Map`s are also translated into directories
- `Text` values or fields are translated into files
- `Optional` values are omitted if `None`

For example, the following Dhall record:

    { dir = { `hello.txt` = "Hello\n" }
    , `goodbye.txt`= Some "Goodbye\n"
    , `missing.txt` = None Text
    }

... should translate to this directory tree:

    $ tree result
    result
    ├── dir
    │   └── hello.txt
    └── goodbye.txt

    $ cat result/dir/hello.txt
    Hello

    $ cat result/goodbye.txt
    Goodbye

Use this in conjunction with the Prelude's support for rendering JSON/YAML in "pure Dhall" so that you can generate files containing JSON. For example:

    let JSON =
          https://prelude.dhall-lang.org/v12.0.0/JSON/package.dhall sha256:843783d29e60b558c2de431ce1206ce34bdfde375fcf06de8ec5bf77092fdef7

    in  { `example.json` =
            JSON.render (JSON.array [ JSON.number 1.0, JSON.bool True ])
        , `example.yaml` =
            JSON.renderYAML
              (JSON.object (toMap { foo = JSON.string "Hello", bar = JSON.null }))
        }

... which would generate:

    $ cat result/example.json
    [ 1.0, true ]

    $ cat result/example.yaml
    ! "bar": null
    ! "foo": "Hello"

This utility does not take care of type-checking and normalizing the provided expression. This will raise a `FilesystemError` exception upon encountering an expression that cannot be converted as-is.

newtype FilesystemError Source #

This error indicates that you supplied an invalid Dhall expression to the `toDirectoryTree` function. The Dhall expression could not be translated to a directory tree.

Constructors

FilesystemError |

Fields

- unexpectedExpression :: Expr Void Void

#### Instances

Instances details

Exception FilesystemError Source # |
Instance details Defined in Dhall.DirectoryTree Methods toException :: FilesystemError -> SomeException Source # fromException :: SomeException -> Maybe FilesystemError Source # displayException :: FilesystemError -> String Source #
Show FilesystemError Source # |
Instance details Defined in Dhall.DirectoryTree Methods showsPrec :: Int -> FilesystemError -> ShowS Source # show :: FilesystemError -> String Source # showList :: [FilesystemError] -> ShowS Source #