diff options
author | Lars Wirzenius <liw@liw.fi> | 2014-11-22 18:18:35 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2014-11-22 18:18:35 +0200 |
commit | 8208026cf7eb3e30217ebd76424378f1afef4cdd (patch) | |
tree | 1f22c36ab81e18c20876dfcffc65c98aa9861f10 | |
parent | 0c1cecc2adb685e444e921507caf5b713f9e3d16 (diff) | |
download | jt-8208026cf7eb3e30217ebd76424378f1afef4cdd.tar.gz |
Move command attach to a separate class
-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.''' |