Fix editor config when an argument with a space is used (#953)

* Fix editor config when an argument with a space is used
* skip broken test on windows
* fix jrnl not behaving nicely with testing suite
* fix argument parsing for test suite
* fix one windows test, disable one windows test
This commit is contained in:
Jonathan Wren 2020-05-23 15:56:31 -07:00 committed by GitHub
parent e6f828214b
commit a4d020423f
5 changed files with 72 additions and 10 deletions

View file

@ -194,11 +194,14 @@ def parse_args(args=None):
help="Opens an interactive interface for deleting entries.",
)
if not args:
args = []
# Handle '-123' as a shortcut for '-n 123'
num = re.compile(r"^-(\d+)$")
if args is None:
args = sys.argv[1:]
return parser.parse_args([num.sub(r"-n \1", a) for a in args])
args = [num.sub(r"-n \1", arg) for arg in args]
return parser.parse_args(args)
def guess_mode(args, config):
@ -300,6 +303,9 @@ def configure_logger(debug=False):
def run(manual_args=None):
if manual_args is None:
manual_args = sys.argv[1:]
args = parse_args(manual_args)
configure_logger(args.debug)

View file

@ -9,6 +9,7 @@ from string import punctuation, whitespace
import subprocess
import sys
import tempfile
import textwrap
from typing import Callable, Optional
import unicodedata
@ -172,10 +173,17 @@ def get_text_from_editor(config, template=""):
try:
subprocess.call(
shlex.split(config["editor"], posix="win" not in sys.platform) + [tmpfile]
shlex.split(config["editor"], posix="win32" not in sys.platform) + [tmpfile]
)
except AttributeError:
subprocess.call(config["editor"] + [tmpfile])
except Exception as e:
error_msg = f"""
{ERROR_COLOR}{str(e)}{RESET_COLOR}
Please check the 'editor' key in your config file for errors:
{repr(config['editor'])}
"""
print(textwrap.dedent(error_msg).strip(), file=sys.stderr)
exit(1)
with open(tmpfile, "r", encoding="utf-8") as f:
raw = f.read()