ERDot icon indicating copy to clipboard operation
ERDot copied to clipboard

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

Open ckhung opened this issue 3 years ago • 2 comments

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!

ckhung avatar May 02 '21 03:05 ckhung

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

ehne avatar May 02 '21 04:05 ehne

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

ckhung avatar May 06 '21 06:05 ckhung