Use case: interrogative commands, whose result is often used as branching points in-code, where we don't usually want to see the output and do expect frequent failures.
if run("dpkg --list | grep packagename", quiet=True).failed:
# install packagename
Implemented with quiet: today, was surprisingly easy once I stopped making dumb mistakes.
Then went back and reread and realized I'd been thinking about primarily setting it up as a kwarg. This is probably smart because (at least IME) most uses of the pattern being aliased here wrap single run/sudo statements, not large blocks. Having a kwarg would thus prevent lots of needless extra lines+indents.
OTOH having only a kwarg means that block level use is still not as easy as it could be.
Here's a brainstorm of all possible related things we could add here:
I'm also not a huge fan of quiet -- it is simple but only really implies the output hiding, not the warn_only. But I can't think of other shortish terms that would imply both (and possibly work well after with, though if we just go the kwarg route that's not as big a deal.)
Gonna go with quiet for now, as both kwarg and contextmanager, and leave it at that. Better name can wait for fab 2.
Add quiet contextmanager and run/sudo kwarg.
Implementation of the kwarg was mildly annoying as I didn't see any elegant solution besides literally using the contextmanager within operations._run_command, so now that's all indented more. Meh. It works, trying to "honor" quietness manually would've been duplicative and error prone and more code besides.
Not entirely sure why I skipped out on a non-quiet warn-only option; sure it's not quite as common as the "fully quiet" use case, but there are still times when you want it, and "don't fail fast" is probably a concrete enough concept by itself to merit its own context manager & kwarg.
Will see how complicated it is to add that in on top.
EDIT: also, going with warn_only for kwarg and context manager, even though warn is less verbose. I felt it was better to be consistent with the current API/nomenclature. Invoke, and thus Fab 2, (will) use just warn.
Add missing kwarg-oriented tests re #627
Add warn_only kwarg/context manager re #627