+# Define some additional commands
+
+class LocalHelpCommand (Command):
+ """Called with an argument, prints that command's documentation.
+
+ With no argument, lists all available help topics as well as any
+ undocumented commands.
+ """
+ def __init__(self):
+ super(LocalHelpCommand, self).__init__(name='help', help=self.__doc__)
+ # We set .arguments now (vs. using th arguments option to __init__),
+ # to overwrite the default help argument. We don't override
+ # :meth:`cmd.Cmd.do_help`, so `help --help` is not a valid command.
+ self.arguments = [
+ Argument(name='command', type='string', optional=True,
+ help='The name of the command you want help with.')
+ ]
+
+ def _run(self, hooke, inqueue, outqueue, params):
+ raise NotImplementedError # cmd.Cmd already implements .do_help()
+
+class LocalExitCommand (Command):
+ """Exit Hooke cleanly.
+ """
+ def __init__(self):
+ super(LocalExitCommand, self).__init__(
+ name='exit', aliases=['quit', 'EOF'], help=self.__doc__,
+ arguments = [
+ Argument(name='force', type='bool', default=False,
+ callback=StoreValue(True), help="""
+Exit without prompting the user. Use if you save often or don't make
+typing mistakes ;).
+""".strip()),
+ ])
+
+ def _run(self, hooke, inqueue, outqueue, params):
+ """The guts of the `do_exit/_quit/_EOF` commands.
+
+ A `True` return stops :meth:`.cmdloop` execution.
+ """
+ _exit = True
+ if params['force'] == False:
+ # TODO: get results of hooke.playlists.current().is_saved()
+ is_saved = True
+ msg = 'Exit?'
+ default = True
+ if is_saved == False:
+ msg = 'You did not save your playlist. ' + msg
+ default = False
+ outqueue.put(BooleanRequest(msg, default))
+ result = inqueue.get()
+ assert isinstance(result, BooleanResponse)
+ _exit = result.value
+ if _exit == True:
+ raise Exit()
+
+