This commit is contained in:
Manuel Ebert 2015-04-21 15:49:27 +02:00
parent ca76077e09
commit 07fbf73dee
4 changed files with 13 additions and 22 deletions

View file

@ -18,7 +18,7 @@ The configuration file is a simple JSON file with the following options and can
- ``journals`` - ``journals``
paths to your journal files paths to your journal files
- ``editor`` - ``editor``
if set, executes this command to launch an external editor for writing your entries, e.g. ``vim``. Some editors require special options to work properly, see :doc:`FAQ <recipes>` for details. This value can either be a string such as the earlier ``"editor": "vim"`` example or ``"editor": ["vim", "+set ft=markdown"]`` if you want to pass arguments to the editor. if set, executes this command to launch an external editor for writing your entries, e.g. ``vim``. Some editors require special options to work properly, see :doc:`FAQ <recipes>` for details.
- ``encrypt`` - ``encrypt``
if ``true``, encrypts your journal using AES. if ``true``, encrypts your journal using AES.
- ``tagsymbols`` - ``tagsymbols``

View file

@ -61,7 +61,7 @@ Feature: Zapped bugs should stay dead.
Scenario: Title with an embedded period on DayOne journal Scenario: Title with an embedded period on DayOne journal
Given we use the config "dayone.yaml" Given we use the config "dayone.yaml"
When we run "jrnl 04-24-2014: Ran 6.2 miles today in 1:02:03. I'm feeling sore because I forgot to stretch." When we run "jrnl 04-24-2014: "Ran 6.2 miles today in 1:02:03. I'm feeling sore because I forgot to stretch.""
Then we should see the message "Entry added" Then we should see the message "Entry added"
When we run "jrnl -1" When we run "jrnl -1"
Then the output should be Then the output should be

View file

@ -1,3 +1,6 @@
from __future__ import unicode_literals
from __future__ import absolute_import
from behave import given, when, then from behave import given, when, then
from jrnl import cli, install, Journal, util from jrnl import cli, install, Journal, util
from jrnl import __version__ from jrnl import __version__
@ -12,23 +15,11 @@ try:
except ImportError: except ImportError:
from cStringIO import StringIO from cStringIO import StringIO
import tzlocal import tzlocal
import shlex
def _parse_args(command): def ushlex(command):
nargs = [] return map(lambda s: s.decode('UTF8'), shlex.split(command.encode('utf8')))
concats = []
for a in command.split()[1:]:
if a.startswith("'") and a.endswith("'"):
nargs.append(a.strip("'"))
elif a.startswith("'"):
concats.append(a.strip("'"))
elif a.endswith("'"):
concats.append(a.strip("'"))
nargs.append(u" ".join(concats))
concats = []
else:
nargs.append(a)
return nargs
def read_journal(journal_name="default"): def read_journal(journal_name="default"):
@ -62,7 +53,7 @@ def set_config(context, config_file):
@when('we run "{command}" and enter "{inputs}"') @when('we run "{command}" and enter "{inputs}"')
def run_with_input(context, command, inputs=None): def run_with_input(context, command, inputs=None):
text = inputs or context.text text = inputs or context.text
args = _parse_args(command) args = ushlex(command)[1:]
buffer = StringIO(text.strip()) buffer = StringIO(text.strip())
util.STDIN = buffer util.STDIN = buffer
try: try:
@ -74,7 +65,7 @@ def run_with_input(context, command, inputs=None):
@when('we run "{command}"') @when('we run "{command}"')
def run(context, command): def run(context, command):
args = _parse_args(command) args = ushlex(command)[1:]
try: try:
cli.run(args or None) cli.run(args or None)
context.exit_status = 0 context.exit_status = 0

View file

@ -12,6 +12,8 @@ import tempfile
import subprocess import subprocess
import codecs import codecs
import unicodedata import unicodedata
import shlex
PY3 = sys.version_info[0] == 3 PY3 = sys.version_info[0] == 3
PY2 = sys.version_info[0] == 2 PY2 = sys.version_info[0] == 2
@ -121,9 +123,7 @@ def get_text_from_editor(config, template=""):
with codecs.open(tmpfile, 'w', "utf-8") as f: with codecs.open(tmpfile, 'w', "utf-8") as f:
if template: if template:
f.write(template) f.write(template)
editor = config['editor'] subprocess.call(shlex.split(config['editor']) + [tmpfile])
args = editor if isinstance(editor, list) else editor.split()
subprocess.call(args + [tmpfile])
with codecs.open(tmpfile, "r", "utf-8") as f: with codecs.open(tmpfile, "r", "utf-8") as f:
raw = f.read() raw = f.read()
os.close(filehandle) os.close(filehandle)