diff options
author | Lars Wirzenius <liw@liw.fi> | 2015-05-03 21:38:01 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2015-05-03 21:38:01 +0300 |
commit | e28783b968d9dde7489795f1286c862e2de166ad (patch) | |
tree | fb2551b8d932c102f6b8d79dddadfcace218b807 /jt | |
parent | 83313e773d6dc269a6a6ec2e70c51287808d8a23 (diff) | |
download | jt-e28783b968d9dde7489795f1286c862e2de166ad.tar.gz |
Simplify by moving some code into helper method
Diffstat (limited to 'jt')
-rwxr-xr-x | jt | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -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) |