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

stdin/stdout input/output #2

Open
mtijanic opened this issue Sep 24, 2023 · 3 comments
Open

stdin/stdout input/output #2

mtijanic opened this issue Sep 24, 2023 · 3 comments

Comments

@mtijanic
Copy link

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
Copy link
Owner

WilliamDraco commented Sep 25, 2023

New commit for beta of 1.5.0 which adds

  • stdin, which it reverts to if <inputfile> is not a file that exists. (So passing - as a filepath will read stdin
  • stdout, either as the default if read from stdin and no -o was specified, or by specifying -o stdout
  • The above should mean pretty simple std useage without any breakage or change to existing workflows.

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
Copy link
Author

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:

  • nwnt foo.gff should read foo.gff or fail
  • nwnt - should read stdin
  • nwnt (no file argument) should read stdin.

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
Copy link
Owner

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.

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