willghatch/racket-rash

Question: Executing commands inside strings

pmatos opened this issue · 4 comments

When you run docker-machine to create a machine you need to change your environment so that you can control the machine using docker. docker-machine provides the information you need to change the environment.

So, after you create a machine you usually run eval $(docker-machine env my-machine).
I want to do this in rash, but eval doesn't exist and $(...) gets me into racket and rash complains docker-machine in this case is an undefined identifier.

Now, I can do this:

(define machine-name "my-machine")
(define lines (string-split #{docker-machine env $machine-name} #\newline))
(for ([l (in-list lines)])
  ...)

For reference, the output of docker-machine env ... looks like:

export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://18.185.184.7:2376"
export DOCKER_CERT_PATH="/home/pmatos/.docker/machine/machines/test-machine"
export DOCKER_MACHINE_NAME="test-machine"
# Run this command to configure your shell: 
# eval $(/usr/bin/docker-machine env test-machine)

So in the loop above l will take the value of each of these lines. I would like to run them but I can't figure out how to do that. Any help on how to achieve this would be great.

@willghatch Missed #42 , but yes that's the related issue. The output of docker-machine env ... is in my original post. I quote again:

export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://18.185.184.7:2376"
export DOCKER_CERT_PATH="/home/pmatos/.docker/machine/machines/test-machine"
export DOCKER_MACHINE_NAME="test-machine"
# Run this command to configure your shell: 
# eval $(/usr/bin/docker-machine env test-machine)

Since we have #42, feel free to close this one. In the meantime I implemented as you suggested the line parsing in racket and used putenv.

Oh, I'm just noticing now that the eval at the bottom is in a quote. I was thinking it was supposed to pull even more stuff in. It's very likely that I'll write a first-pass posix-support wrapper that just supports export FOO="bar" lines soon and then leave full support for an indeterminate time later. So even if I don't have real posix support for a long time this is likely to happen soon.

Awesome, thanks.