homely icon indicating copy to clipboard operation
homely copied to clipboard

Allow using yesno() as a context manager

Open phodge opened this issue 7 years ago • 0 comments

When setting up a new system, my HOMELY.py asks if I want to install things using yesno() prompts, but then fails with a traceback because the things isn't available via the system package manager.

It'd be nice if yesno() could be used as a context manager like this:

@yesno("Install ack?")
def install_ack():
    installpkg(brew="ack")

The new behaviours you would get with this arrangement are:

  • The question name is taken from the decorated function instead of the first arg
  • If the decorated function raises an exception, the traceback is logged, the saved answer is reset (so you have to decide Y/N next time)
  • script execution continues

The benefits are:

  • If something fails, the whole script doesn't come to a halt
  • You don't have to use -a and answer every question again to disable one thing that was broken

phodge avatar Mar 22 '17 06:03 phodge