From 59ee5ba950dca96d64ef11999e266da661edf8ba Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 22 Nov 2014 19:10:20 +0200 Subject: Make choose_draft use DraftsDirectory --- jt | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/jt b/jt index 13dc739..80c7041 100755 --- a/jt +++ b/jt @@ -124,8 +124,11 @@ class ListCommand(Command): class EditCommand(Command): def run(self, args): - filename = self._app.choose_draft(args) - self._app.edit_file(filename) + if len(args) > 1: + raise cliapp.AppException('Must be given at most one draft ID') + drafts_dir = DraftsDirectory(self._app.drafts_dir()) + pathmame = self._app.choose_draft(drafts_dir, args) + self._app.edit_file(pathname) class AttachCommand(Command): @@ -155,7 +158,8 @@ class RemoveCommand(Command): class FinishCommand(Command): def run(self, args): - draft_mdwn = self._app.choose_draft(args) + drafts_dir = DraftsDirectory(self._app.drafts_dir()) + draft_mdwn = self._app.choose_draft(drafts_dir, args) draft_attch, ext = os.path.splitext(draft_mdwn) assert ext == '.mdwn' @@ -329,21 +333,23 @@ class JournalTool(cliapp.Application): '''Edit a draft journal entry.''' EditCommand(self).run(args) - def choose_draft(self, args): + def choose_draft(self, drafts_dir, args): if len(args) == 0: - drafts = list(self.find_drafts()) + drafts = list(drafts_dir.get_drafts()) if len(drafts) == 1: draft_id, filename = drafts[0] return filename + elif len(drafts) == 0: + raise cliapp.AppException('No drafts to choose from') else: raise cliapp.AppException('Cannot choose entry draft automatically') elif len(args) == 1: - filename = self.draft_name(args[0]) - if not os.path.exists(filename): + pathname = drafts_dir.get_draft_pathname(args[0]) + if not os.path.exists(pathname): raise cliapp.AppException('draft %s does not exist' % args[0]) - return filename + return pathname elif len(args) > 1: - raise cliapp.AppException('Must give only one draft number') + raise cliapp.AppException('Must give at most one draft number') def cmd_attach(self, args): '''Attach files to a journal entry draft.''' -- cgit v1.2.1