From 32774872566e0c29aefec26d8fbc41242afebbef Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 22 Nov 2014 18:19:24 +0200 Subject: Move command remove to a separate class --- jt | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/jt b/jt index 9c54f14..ad02c62 100755 --- a/jt +++ b/jt @@ -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.''' -- cgit v1.2.1