summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2015-05-03 21:38:01 +0300
committerLars Wirzenius <liw@liw.fi>2015-05-03 21:38:01 +0300
commite28783b968d9dde7489795f1286c862e2de166ad (patch)
treefb2551b8d932c102f6b8d79dddadfcace218b807
parent83313e773d6dc269a6a6ec2e70c51287808d8a23 (diff)
downloadjt-e28783b968d9dde7489795f1286c862e2de166ad.tar.gz
Simplify by moving some code into helper method
-rwxr-xr-xjt16
1 files changed, 10 insertions, 6 deletions
diff --git a/jt b/jt
index e13b36a..a9653ae 100755
--- a/jt
+++ b/jt
@@ -105,14 +105,9 @@ class NewCommand(Command):
'''
def run(self, args):
- if not args:
- raise cliapp.AppException('Usage: journal-note new TITLE')
+ self._check_args_and_settings(args)
- self._app.settings.require('source')
topic = self._app.settings['topic']
- if topic and not self._topic_page_exists(topic):
- raise cliapp.AppException('Topic %s does not exist yet' % topic)
-
values = {
'title': args[0],
'date': time.strftime('%Y-%m-%d %H:%M', self._app.now_tuple),
@@ -125,6 +120,15 @@ class NewCommand(Command):
self._get_new_note_template() % values)
self._app.edit_file(drafts_dir.get_draft_pathname(draft_id))
+ def _check_args_and_settings(self, args):
+ if not args:
+ raise cliapp.AppException('Usage: journal-note new TITLE')
+
+ self._app.settings.require('source')
+ topic = self._app.settings['topic']
+ if topic and not self._topic_page_exists(topic):
+ raise cliapp.AppException('Topic %s does not exist yet' % topic)
+
def _topic_page_exists(self, topic):
pathname = os.path.join(self._app.settings['source'], topic + '.mdwn')
return os.path.exists(pathname)