diff options
author | Lars Wirzenius <liw@liw.fi> | 2014-11-22 18:19:24 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2014-11-22 18:19:24 +0200 |
commit | 32774872566e0c29aefec26d8fbc41242afebbef (patch) | |
tree | a98158eacc79e677453a2c85315c9819b24b5e3f | |
parent | 8208026cf7eb3e30217ebd76424378f1afef4cdd (diff) | |
download | jt-32774872566e0c29aefec26d8fbc41242afebbef.tar.gz |
Move command remove to a separate class
-rwxr-xr-x | jt | 26 |
1 files changed, 16 insertions, 10 deletions
@@ -108,6 +108,21 @@ class AttachCommand(Command): shutil.copy(filename, dirname) +class RemoveCommand(Command): + + def run(self, args): + if not args: + raise cliapp.AppException('Usage: journal-note remove ID') + + filename = self._app.draft_name(args[0]) + os.remove(filename) + + dirname, ext = os.path.splitext(filename) + assert ext == '.mdwn' + if os.path.exists(dirname): + shutil.rmtree(dirname) + + class JournalTool(cliapp.Application): cmd_synopsis = { @@ -216,16 +231,7 @@ class JournalTool(cliapp.Application): def cmd_remove(self, args): '''Remove a draft.''' - - if not args: - raise cliapp.AppException('Usage: journal-note remove ID') - filename = self.draft_name(args[0]) - os.remove(filename) - - dirname, ext = os.path.splitext(filename) - assert ext == '.mdwn' - if os.path.exists(dirname): - shutil.rmtree(dirname) + RemoveCommand(self).run(args) def cmd_finish(self, args): '''Publish a draft journal entry.''' |