summaryrefslogtreecommitdiff
path: root/subplot
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-11-14 16:28:21 +0200
committerLars Wirzenius <liw@liw.fi>2020-11-16 11:11:02 +0200
commit471fad9ef42b6176be083eb876dd4fbe85ecd1c1 (patch)
tree1875c05df3eb6aef96fd4c43746f617da4674b0c /subplot
parent04696e960745320dbec7b5b31713b5a280da3ad5 (diff)
downloadjt2-471fad9ef42b6176be083eb876dd4fbe85ecd1c1.tar.gz
feat: add "jt edit" to edit a draft with a chosen editor
Also, add some debugging log statements that were needed while making this change.
Diffstat (limited to 'subplot')
-rw-r--r--subplot/jt.py16
-rw-r--r--subplot/jt.yaml11
2 files changed, 25 insertions, 2 deletions
diff --git a/subplot/jt.py b/subplot/jt.py
index b9a7122..380cde4 100644
--- a/subplot/jt.py
+++ b/subplot/jt.py
@@ -2,6 +2,13 @@ import logging
import os
+def create_script(ctx, filename=None):
+ get_file = globals()["get_file"]
+ text = get_file(filename)
+ open(filename, "wb").write(text)
+ os.chmod(filename, 0o755)
+
+
def run_jt_init(ctx, dirname=None, journalname=None, title=None):
runcmd_run = globals()["runcmd_run"]
runcmd_run(ctx, [_binary("jt"), "init", dirname, journalname, title])
@@ -24,6 +31,15 @@ def run_jt_new(ctx, title=None, dirname=None):
)
+def run_jt_edit(ctx, editor=None, dirname=None):
+ runcmd_run = globals()["runcmd_run"]
+ env = dict(os.environ)
+ env["JT_LOG"] = "jt"
+ runcmd_run(
+ ctx, [_binary("jt"), "edit", "--dirname", dirname, "--editor", editor], env=env
+ )
+
+
def run_jt_finish(ctx, dirname=None):
runcmd_run = globals()["runcmd_run"]
runcmd_run(ctx, [_binary("jt"), "finish", "--dirname", dirname])
diff --git a/subplot/jt.yaml b/subplot/jt.yaml
index 5ed6ed3..6d10a3a 100644
--- a/subplot/jt.yaml
+++ b/subplot/jt.yaml
@@ -1,3 +1,6 @@
+- given: "an executable script {filename}"
+ function: create_script
+
- when: I invoke jt init (?P<dirname>\S+) (?P<journalname>\S+) "(?P<title>.*)"
regex: true
function: run_jt_init
@@ -11,6 +14,10 @@
- when: I invoke jt new "{title:text}" --editor=none --dirname={dirname}
function: run_jt_new
+- when: "I invoke jt edit --editor={editor} --dirname={dirname}"
+ regex: false
+ function: run_jt_edit
+
- when: I invoke jt finish --dirname={dirname}
function: run_jt_finish
@@ -30,7 +37,7 @@
- then: there is one draft in {dirname}
function: journal_has_one_draft
-- then: draft {draftno} in {dirname} contains "{pattern}"
+- then: draft {draftno} in {dirname} contains "{pattern:text}"
function: draft_contains_string
- then: there are no journal entries in {dirname}
@@ -39,5 +46,5 @@
- then: there is one journal entry in {dirname}, at {variable}
function: journal_has_one_entry
-- then: file <{variable}> contains "{pattern}"
+- then: file <{variable}> contains "{pattern:text}"
function: file_contains