summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2014-11-22 19:10:20 +0200
committerLars Wirzenius <liw@liw.fi>2014-11-22 19:10:20 +0200
commit59ee5ba950dca96d64ef11999e266da661edf8ba (patch)
tree0b95049e19f67b618ada686ce3c0828f75e22359
parent974e0db3e39a5d037cc0c60411aa6f12f8f2c115 (diff)
downloadjt-59ee5ba950dca96d64ef11999e266da661edf8ba.tar.gz
Make choose_draft use DraftsDirectory
-rwxr-xr-xjt24
1 files 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.'''