[rfc] UIFactory.is_interactive()

Andrew Bennetts andrew.bennetts at canonical.com
Tue Nov 24 04:41:39 GMT 2009


Martin Pool wrote:
> For background,
> https://code.launchpad.net/~bialix/bzr/shelve-no-tty/+merge/14905
> wants to make 'bzr shelve' not ask any interactive questions if there
> is no tty.
> 
> More generally I think the ui factory should be able to tell
> application code whether it can interact with the user or not.  For a

I agree.

> text ui, this would probably correlate to having a tty; for server
> things it will always be false; for guis presumably always true.  Then
> we can have code generally doing
> 
>   if ui_factory.is_interactive():
>     if not ui_factory.get_boolean("really delete everything?"):
>       return
>   delete_everything()
> 
> This somewhat violates "don't look before you leap" but it's probably
> worthwhile to avoid thinking about interactive stuff before you do it.

Maybe a less LBYL solution would be:

    if not ui_factory.get_boolean("really delete everything?", default=True):
        return
    delete_everything()

Although perhaps “default choice” is not precisely the same concept as “choice
to take when non-interactive”, it's probably close enough.

Anyway, I agree with the basic goal (“the ui factory should be able to tell
application code whether it can interact with the user or not”), whatever the
spelling.

-Andrew.




More information about the bazaar mailing list