Convenience tweaks re: expected failures #627

Closed
bitprophet opened this Issue Apr 26, 2012 · 4 comments

Projects

None yet

1 participant

@bitprophet
Member
  • quiet kwarg to run/sudo/local which:
    • hides everything

    • sets warn_only=True

    • 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.

    • Example:

      if run("dpkg --list | grep packagename", quiet=True).failed:
          # install packagename
      
  • maybe also a warn_only() contextmanager shortcut to settings(warn_only=True)?
    • first contextmanager with no parameterization, kinda ugly needing the parens still (unless I'm being dumb)
      • edit: I guess it could be an instance of a contextmanager class. slightly longer definition code, but easier invoke.
    • Maybe add on the output hiding so it's a contextmanager variant of quiet? with quiet():? with silence()?
@bitprophet
Member

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:

  • with quiet: (implying warn_only)
  • runner(xxx, quiet=True) (ditto)
  • with warn_only:
  • runner(xxx, warn_only=True)

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.)

@bitprophet
Member

Gonna go with quiet for now, as both kwarg and contextmanager, and leave it at that. Better name can wait for fab 2.

@bitprophet
Member

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.

@bitprophet
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment