bblfshd icon indicating copy to clipboard operation
bblfshd copied to clipboard

Passing local file to parse command

Open dustinmichels opened this issue 6 years ago • 3 comments

Hi,

I realize this may be more of a Docker question than an issue specific to this repo, but I would love an example in the documentation for how to pass a local file to the parse command.

On the Getting Started you list the following command to run an example file included in the container:

docker exec -it bblfshd bblfshctl parse /opt/bblfsh/etc/examples/python.py

I'm having a lot of trouble figuring out how to pass my own file, on my computer, into the container.

Thanks!

dustinmichels avatar Apr 29 '19 17:04 dustinmichels

Hi @dustinmichels!

It is indeed Docker-related, but we should clarify it in the documentation anyway.

You achieve similar results in a few different ways, please pick one that suits your workflow better.

Mount the directory to bblfshd container

The first way is to expose one of your directories to bblfshd directly. It is the simplest option, but if you don't trust either Docker or bblfshd, you should not expose your whole FS or home directory to the container. A safe middle ground may be to expose an empty directory, or the directory that you want to analyze.

It can be done by adding a -v /your/local/path:/project flag to the docker run command. The /your/local/path is the directory on your host, and the /project is the mount path inside the container. So the full example will look like:

docker run -d --name bblfshd --privileged -v /home/user/project:/project  bblfsh/bblfshd:v2.12.1-drivers
docker exec -it bblfshd bblfshctl parse /project/file.py

Note that you don't need to add a -p 9432:9432 directive if you will only parse with docker exec.

Use bblfshctl

This is a more secure option that requires a bblfshctl tool on the host (you can find it on the releases page).

You run bblfshd as usual, make sure to pass -p 9432:9432 option to docker run, and then run the parse from the host directly:

bblfshctl parse ./file.py

It will automatically connect to localhost:9432 that is exposed by the container.

Use one of the clients

Go client has a simple bblfsh-cli tool that can parse the files and dump the UAST in different formats. It's mostly the same as bblfshctl in this regard, but also provides a code that is easy to follow and can be adapted to your needs.

The same example exists for Python client as well.

Running it is similar to running bblfsctl on the host - you only need to expose the port from the container.

dennwc avatar Apr 29 '19 19:04 dennwc

Thank you so much for the detailed reply. Much appreciated!

dustinmichels avatar May 01 '19 18:05 dustinmichels

Thank you so much for the detailed reply. Much appreciated!

Agreed, this is great, and in fact I would like to turn all of https://github.com/bblfsh/bblfshd/issues/282#issuecomment-487713139 into a new entry on the documentation site. I'll look into that now.

creachadair avatar May 02 '19 17:05 creachadair