From e28783b968d9dde7489795f1286c862e2de166ad Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 3 May 2015 21:38:01 +0300 Subject: Simplify by moving some code into helper method --- jt | 16 ++++++++++------ 1 file 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) -- cgit v1.2.1