summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2014-11-22 18:18:35 +0200
committerLars Wirzenius <liw@liw.fi>2014-11-22 18:18:35 +0200
commit8208026cf7eb3e30217ebd76424378f1afef4cdd (patch)
tree1f22c36ab81e18c20876dfcffc65c98aa9861f10
parent0c1cecc2adb685e444e921507caf5b713f9e3d16 (diff)
downloadjt-8208026cf7eb3e30217ebd76424378f1afef4cdd.tar.gz
Move command attach to a separate class
-rwxr-xr-xjt31
1 files changed, 18 insertions, 13 deletions
diff --git a/jt b/jt
index 59e4c46..9c54f14 100755
--- a/jt
+++ b/jt
@@ -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.'''