From 471fad9ef42b6176be083eb876dd4fbe85ecd1c1 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 14 Nov 2020 16:28:21 +0200 Subject: 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. --- subplot/jt.py | 16 ++++++++++++++++ subplot/jt.yaml | 11 +++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'subplot') 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\S+) (?P\S+) "(?P.*)" 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 -- cgit v1.2.1