Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can Dhall be used as a replacement for bash? #97

Closed
AnthonyJacob opened this issue Aug 8, 2017 · 13 comments
Closed

Can Dhall be used as a replacement for bash? #97

AnthonyJacob opened this issue Aug 8, 2017 · 13 comments

Comments

@AnthonyJacob
Copy link

AnthonyJacob commented Aug 8, 2017

There is a Dhall to bash compiler. I know multiple tools that use bash as a configuration language : herbstluft window manager, kakoune text editor.

Is it possible to use Dhall to generate those config.sh files? Do you think it is a wise idea?

@Gabriella439
Copy link
Collaborator

Could you clarify what you need that the existing dhall-to-bash tool doesn't do? I'm not familiar with these configuration languages

@AnthonyJacob
Copy link
Author

AnthonyJacob commented Aug 12, 2017

config example

@Gabriella439
Copy link
Collaborator

The file you linked to is not a Bash script, though. It looks like a kakoune-specific configuration language, similar to vimscript

@Gabriella439
Copy link
Collaborator

I'll close this for now because the scope of this task is not clear. Feel free to reopen if you still have questions

@docteurklein
Copy link

The title looked pretty clear to me! Even tho the linked example was totally not a bash example.

I'm curious as well to know how much can dhall-to-bash do to reduce my necessity to write bash.
Apart from the trivial [1, 2, 3] examples, cause I think I can do that without dhall :)

I think that's one of the big problems with all the dhall-to-* tools out there: There is zero example that shows a non-trivial usage, only basic [1, 2, 3]! People don't have problems generating list of integers in real life (and if they do, gnu-coretools seq 1 3 is pretty good at it).

Sorry for the rant, I'm very interested in the promise behind dhall, but for now I struggle to use it to solve real life problems.

@Gabriella439
Copy link
Collaborator

@docteurklein: The answer is: not too much. dhall-to-bash can't run Bash commands for you and even if you try to translate "pure" Bash commands to Dhall (like grep/sed) you won't have much luck because Dhall is a very restricted language where Text values are opaque.

dhall is most commonly used to replace large and repetitive YAML files for ops-related tooling. See:

Those should give you some idea of what use cases that Dhall is focusing on.

I only implemented dhall-to-bash because (A) somebody asked for it and (B) it was really easy to implement, but it is not really one of the core pillars of the Dhall ecosystem. The Dhall integrations with YAML/JSON and Ops tools like Kubernetes are the key integrations of the Dhall ecosystem and when Dhall gets Python/Go bindings then those will help as well.

@docteurklein
Copy link

thanks :)

@Gabriella439
Copy link
Collaborator

@docteurklein: You're welcome! 🙂

@ari-becker
Copy link

I'm curious as well to know how much can dhall-to-bash do to reduce my necessity to write bash.
Apart from the trivial [1, 2, 3] examples, cause I think I can do that without dhall :)

@docteurklein The purpose of the dhall-to-bash tool has more to do with rounding out the experience for people who have already transitioned most of their configuration files to Dhall. To take a simple example, let's say I have a Dhall configuration file which defines Kubernetes-related configuration, including which Kubernetes namespace is being used. So if in a bash script, you would need to write:

kubectl --namespace=<what goes here?> get pods

you can use the namespace by something like:

eval $(dhall-to-bash --declare kubernetes_namespace <<< '(./Config.dhall).path.to.namespace')
kubectl --namespace=${kubernetes_namespace} get pods

You may note that you could replace dhall-to-bash above with kubernetes_namespace=$(dhall-to-text <<< '(./Config.dhall).path.to.namespace') and the example would work almost as nicely. The dhall-to-bash tool mostly makes your life easier if you're extracting Optionals or Lists from a Dhall config into a Bash variable, which dhall-to-text doesn't know how to do on it's own.

The dhall-to-bash tool isn't for replacing the kubectl get pods bit.

Hope this helps

@PierreR
Copy link
Contributor

PierreR commented Mar 28, 2019

@Gabriel439 FWIW I kind of find dhall-to-bash more useful than dhall-kubernetes so far probably because I don't quite see how dhall-kubernetes is useful in the context of helm.

On the other hand, if you wish to move out configuration out of bash scripts then in theory dhall-to-bash seems to make quite a lot of sense. The only issue is the lack of support for basic dhall features such as union types.

I fear the problem with Yaml in the context of Ops tools is the fact that most of these configurations are not plain Yaml anymore (Ansible, Terraform, ...) and for all of these Yaml++ DSLs there are currently no dhall bindings at all ;-)

Anyway I have just written this because I still have hope that dhall-to-bash fits a nice use case.

@Gabriella439
Copy link
Collaborator

@PierreR: Actually, now that Dhall supports empty alternatives then that allows dhall-to-bash to render empty alternatives as strings

@Gabriella439
Copy link
Collaborator

Also, I ran into another use case for dhall-to-bash at work recently. We had a list of values that needed to be shared between a Haskell program and a Bash program. I stored the list of values in a Dhall configuration file so that I could read it into Bash using dhall-to-bash and read it into Haskell using the dhall Haskell package.

Gabriella439 added a commit that referenced this issue Mar 30, 2019
... as mentioned here: #97 (comment)

Similar to `dhall-json`, this translates empty alternatives to
strings of the same name
@Gabriella439
Copy link
Collaborator

Here is the pull request to add enum support to dhall-to-bash: #873

Gabriella439 added a commit that referenced this issue Mar 30, 2019
... as mentioned here: #97 (comment)

Similar to `dhall-json`, this translates empty alternatives to
strings of the same name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants