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

make pipe work (read from stdin and write to stdout) #7

Open
ckhung opened this issue May 2, 2021 · 2 comments
Open

make pipe work (read from stdin and write to stdout) #7

ckhung opened this issue May 2, 2021 · 2 comments

Comments

@ckhung
Copy link

ckhung commented May 2, 2021

Hi, I would like to pipe the output of ERDot directly to dot like this:
erdot -o - example.erd.json | dot -Tsvg > example.svg
But presently these extraneous messages:

loaded example.erd.json
generated .dot code
saved graphvis dot code to -!

are mixed into the dot output and therefore the pipe fails.
Can you please move them to stderr instead of stdout?
Or maybe add an -q option (quiet) to suppress these extraneous messages?

Also, I would like to pipe the output of some other program into ERDot like this:

python3 json2erd.py < example.sqp.json | erdot > example.dot

Can you please make the input file name optional?
So in the absence of the input file name, erdot should read from stdin.
You can do that easily with fileinput() like this:

jsonLoaded = json.loads(''.join(fileinput.input(args.jsonfile)))

See this gist for a full example.

In fact the json2erd.py script I created:
https://gist.github.com/ckhung/c208ad5b72e7ebe216fd0bfc7fb1cb7a
is meant to convert the output of a sql ddl parser (such as iamcal/SQLParser)
to the input of an ER diagram renderer (such as your ehne/ERDot )
and it would be nice if the entire chain of commands can be streamlined by pipes.
My script also uses fileinput() to achieve the "input file or stdin" effect.

Thanks!

@ehne
Copy link
Owner

ehne commented May 2, 2021

Hello, thanks for submitting an issue.

Version 2.2.0 supports a -q option, this will hide those extra messages, and you'll be able to pipe it directly into dot.

In terms of reading input from stdin, I'll have to do a bit more research into how that works specifically in click, which the library I'm using to handle the cli functions.

thanks,
-ehne

@ckhung
Copy link
Author

ckhung commented May 6, 2021

I think they support it after reading the "File Arguments" section of https://click.palletsprojects.com/en/7.x/arguments/?highlight=stdin

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

2 participants