diff options
-rwxr-xr-x | jt | 31 |
1 files changed, 18 insertions, 13 deletions
@@ -91,6 +91,23 @@ class EditCommand(Command): self._app.edit_file(filename) +class AttachCommand(Command): + + def run(self, args): + if len(args) < 2: + raise cliapp.AppException('Usage: journal-note attach ID file...') + + filename = self._app.draft_name(args[0]) + + dirname, ext = os.path.splitext(filename) + assert ext == '.mdwn' + + if not os.path.exists(dirname): + os.mkdir(dirname) + for filename in args[1:]: + shutil.copy(filename, dirname) + + class JournalTool(cliapp.Application): cmd_synopsis = { @@ -195,19 +212,7 @@ class JournalTool(cliapp.Application): def cmd_attach(self, args): '''Attach files to a journal entry draft.''' - - if len(args) < 2: - raise cliapp.AppException('Usage: journal-note attach ID file...') - - filename = self.draft_name(args[0]) - - dirname, ext = os.path.splitext(filename) - assert ext == '.mdwn' - - if not os.path.exists(dirname): - os.mkdir(dirname) - for filename in args[1:]: - shutil.copy(filename, dirname) + AttachCommand(self).run(args) def cmd_remove(self, args): '''Remove a draft.''' |