3 """The `engine` module provides :class:`EnginePlugin` and several
4 associated :class:`hooke.command.Command`\s for basic
5 :class:`~hooke.hooke.Hooke` and :class:`~hooke.engine.CommandEngine`
9 from ..command import CommandExit, Exit, Command, Argument
10 from ..interaction import BooleanRequest
14 class EnginePlugin (Builtin):
16 super(EnginePlugin, self).__init__(name='engine')
18 ExitCommand(self), HelpCommand(self)]
21 class ExitCommand (Command):
22 """Exit Hooke cleanly.
24 def __init__(self, plugin):
25 super(ExitCommand, self).__init__(
28 Argument(name='force', type='bool', default=False,
30 Exit without prompting the user. Use if you save often or don't make
34 help=self.__doc__, plugin=plugin)
36 def _run(self, hooke, inqueue, outqueue, params):
37 """Exit Hooke, prompting if there are unsaved changes.
40 if params['force'] == False:
41 not_saved = [p.name for p in hooke.playlists
42 if p.is_saved() == False]
45 if len(not_saved) > 0:
46 msg = 'Unsaved playlists (%s). %s' \
47 % (', '.join([str(p) for p in not_saved]), msg)
49 outqueue.put(BooleanRequest(msg, default))
50 result = inqueue.get()
51 assert result.type == 'boolean'
55 # TODO: check for unsaved config file
60 class HelpCommand (Command):
61 """Called with an argument, prints that command's documentation.
63 With no argument, lists all available help topics as well as any
64 undocumented commands.
66 def __init__(self, plugin):
67 super(HelpCommand, self).__init__(
68 name='help', help=self.__doc__, plugin=plugin)
69 # We set .arguments now (vs. using th arguments option to __init__),
70 # to overwrite the default help argument. We don't override
71 # :meth:`cmd.Cmd.do_help`, so `help --help` is not a valid command.
73 Argument(name='command', type='string', optional=True,
74 help='The name of the command you want help with.')
77 def _run(self, hooke, inqueue, outqueue, params):
78 if params['command'] == None:
79 outqueue.put(sorted([c.name for c in hooke.commands]))
81 outqueue.put(hooke.command_by_name[params['command']].help())