Dhall-haskell: dhall-json: provide flag -o, --output for writing to file

Created on 11 Sep 2019  路  6Comments  路  Source: dhall-lang/dhall-haskell

Not having flag -o or --output can cause problems, especially for a project that use docker-compose as their development workflow. For example:

Given this docker-compose.yml

version: "3"
services:
  dhall-json:
    image: dhallhaskell/dhall-json
    entrypoint: [dhall-to-json]
    command: [--file, syntaxes/Dhall.dhall, --pretty]
    volumes:
      - ./syntaxes:/syntaxes:ro

If I run this

docker-compose run --rm --user $(id --user) dhall-json > Dhall.tmLanguage.json

it works but when there is an error, that error will be redirected to Dhall.tmLanguage.json and not printed in stderr.
There is a mode to disable pseudo-tty allocation, but it doesn't solve the problem. For example:

docker-compose run --rm -T --user $(id --user) dhall-json > Dhall.tmLanguage.json

the error is shown in the terminal but when it's succeeded, the results are not written into Dhall.tmLanguage.json.


Also, since the official docker image dhallhaskell/dhall-json is a minimal image (don't provide shell), this docker-compose file will not works:

version: "3"
services:
  dhall-json:
    image: dhallhaskell/dhall-json
    command: [/bin/sh, -c, "dhall-to-json --file syntaxes/Dhall.dhall --pretty > dist/Dhall.tmLanguage.json"]
    volumes:
      - ./dist:/dist:rw
      - ./syntaxes:/syntaxes:ro
$ docker-compose run --rm --user $(id --user) dhall-json
Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory": unknown

Though I still prefer the official docker image to be minimal

References

https://docs.docker.com/compose/reference/run/

enhancement

All 6 comments

A --output flag seems easy enough to add, but I wonder whether it wouldn't be even easier to fix the docker image to include a shell or some other program that can redirect dhall-json's output to a file?

It is possible, but my preference is to add an --input and --output flag so that there is no risk of interference from other output over the stdin/stdout channels

However, just in case you're interested in how we'd update the container built by CI, the relevant code is here:

https://github.com/dhall-lang/dhall-haskell/blob/37f819c8bb8e7f7e772945cb9bde76b14110772a/nix/shared.nix#L596-L600

... and this section of the Nixpkgs manual explains some common things you can do with the buildImage function:

https://nixos.org/nixpkgs/manual/#ssec-pkgs-dockerTools-buildImage

It is possible, but my preference is to add an --input and --output flag so that there is no risk of interference from other output over the stdin/stdout channels

The --input flag(s) would replace the existing --file option (which we could keep for compatibility)? And I assume we want this for all the executables in dhall-json?

@sjakobi: We might not necessarily want to replace --file because part of the reason the flag exists is to set the root directory relative to the file's path

I think in the short term we can just add the --output flag for now as was requested and then figure out the UX for input separately

Sounds good. I'll make a patch.

Closing this as #1304 addressed the original feature request.

If there's a need for an --input flag as mentioned in https://github.com/dhall-lang/dhall-haskell/issues/1303#issuecomment-530184135, we can discuss this in a new issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SiriusStarr picture SiriusStarr  路  5Comments

SiriusStarr picture SiriusStarr  路  5Comments

quasicomputational picture quasicomputational  路  4Comments

Profpatsch picture Profpatsch  路  4Comments

chris-martin picture chris-martin  路  5Comments