WilliamDraco / NWNT

Repository for the GFF<->NWNT conversion tool and library
MIT License
5 stars 1 forks source link

stdin/stdout input/output #2

Open mtijanic opened 1 year ago

mtijanic commented 1 year ago

Should have a way to print the output to stdout, for composability with other tools (eg nwnt foo.gff | grep bar). Arguably this should be the default and an argument or pipe redirect (>) would send it to a file, but if the CLI is meant to be stable then a new flag would work.

Should also be able to take input from stdin, especially in nwnt->gff direction, so you could do nwnt | sed | nwnt for quick edits.

WilliamDraco commented 1 year ago

New commit for beta of 1.5.0 which adds

This is not final yet due to a nwn_gff issue, at least on windows, when writing out gff data to stdout (See issue). But my tests on piping gff->nwnt through stdin/out at least appear to be working.

mtijanic commented 1 year ago

Thanks for the speedy impl! I don't think this is right however:

stdin, which it reverts to if <inputfile> is not a file that exists.

If I do nwnt foo.gff and foo.gff doesn't exist, I'd want to get an error and not have the program block on stdin. IMO:

Also, -o stdout is a bit unfortunate as it doesn't allow you to write to a file called stdout but that's a limitation most can live with (even if not a limitation most tools have)

WilliamDraco commented 1 year ago

As discussed in discord - I was having trouble handling stdin as you describe, but after leaving it a few hours and picking it back up the answer was extremely obvious. New 1.5.1 beta acts as you describe: nwnt or nwnt - reads from stdin (only when piped) nwnt foo.gff attempts to find foo.gff or else quits.

Just to publicise the discussion: -o stdout could be changed to any other string, but stdout was just first-to-mind and extremely unlikely as a genuine filename. 🤷 Will stay as is for now.

Unrelated: Also discovered nwn_gff has issues with piped-in gff data on my machine too. Remains in beta until I determine if it's just me or will require an nwnt-side fix too.