kalekundert / stepwise

Modular, command-line scientific protocols
GNU General Public License v3.0
3 stars 0 forks source link

Allow protocols to output directly to stdout #52

Open kalekundert opened 3 years ago

kalekundert commented 3 years ago

Currently, anything a protocol script writes to stdout is interpreted as a protocol, and errors are generated if it cannot be parsed as such. However, I'd like to be able to do things like:

F=path/to/cond.xlsx
N=$(sw cond count $F)

sw cond $F |
sw gel $N

In other words, the sw cond command has access to information (the number of conditions to test) that could be useful in the rest of the script. This would help prevent bugs where I forget to update these kinds of numbers.

My initial thought for how to do this is to add a enable_direct_output() function to stepwise that toggles a global variable controlling whether the main function will attempt to parse protocol output as a protocol. I have to think more about how such a variable might propogate to subprocesses, though.

It's worth mentioning that the ability to output directly to stdout is one of the main distinctions between "protocols" (e.g. cond, step, reaction) and "subcommands" (e.g. ls, stash, go). This feature weakens that distinction, and suggests that maybe the distinction should be removed altogether. However, I don't think it should be. Another difference is that subcommands can't be shadowed by protocols, and I think that's also important.

kalekundert commented 2 years ago

This would also be helpful for outputting command line usage text. Right now I output this text to stderr to kinda circumvent the whole problem. But it might be better to just use stdout in "not protocol output" mode.