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

Passing local file to parse command #282

Open
dustinmichels opened this issue Apr 29, 2019 · 3 comments
Open

Passing local file to parse command #282

dustinmichels opened this issue Apr 29, 2019 · 3 comments

Comments

@dustinmichels
Copy link

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!

@dennwc
Copy link
Member

dennwc commented Apr 29, 2019

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.

@dustinmichels
Copy link
Author

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

@dennwc dennwc self-assigned this May 2, 2019
@creachadair
Copy link
Contributor

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

Agreed, this is great, and in fact I would like to turn all of #282 (comment) into a new entry on the documentation site. I'll look into that now.

@dennwc dennwc removed their assignment Jul 8, 2019
@creachadair creachadair removed their assignment Feb 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants