mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-06-28 05:26:13 +02:00
Clean up help screen, get rid of util.py (#1027)
* More refactoring of cli.py break up code from cli.py (now in jrnl.py) up into smaller functions get rid of export mode move --encrypt and --decrypt to commands.py clean up the help screen even more update flag name for import * reorganize code, move around lots of functions * clean up import statements * move run function out of cli and into jrnl * rename confusingly named function * move editor function into editor file * rename parse_args.py to args.py to make room for more args functions * Fix error in test suite for windows I accidentally flipped the conditional, so this fixes it. Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com> * Update app description on help screen Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
This commit is contained in:
parent
7c3abb2625
commit
631e08a557
30 changed files with 981 additions and 775 deletions
|
@ -180,7 +180,7 @@ Feature: Basic reading and writing to a journal
|
|||
And the journal should contain "Life is good."
|
||||
But the journal should not contain "I have an @idea"
|
||||
And the journal should not contain "I met with"
|
||||
When we run "jrnl --import -i features/journals/tags.journal"
|
||||
When we run "jrnl --import --file features/journals/tags.journal"
|
||||
Then the journal should contain "My first entry."
|
||||
And the journal should contain "Life is good."
|
||||
And the journal should contain "PROFIT!"
|
||||
|
@ -191,10 +191,11 @@ Feature: Basic reading and writing to a journal
|
|||
And the journal should contain "Life is good."
|
||||
But the journal should not contain "I have an @idea"
|
||||
And the journal should not contain "I met with"
|
||||
When we run "jrnl --import -i features/journals/tags.journal" and pipe
|
||||
When we run "jrnl --import --file features/journals/tags.journal" and pipe
|
||||
"""
|
||||
[2020-07-05 15:00] I should not exist!
|
||||
"""
|
||||
Then the journal should contain "My first entry."
|
||||
And the journal should contain "PROFIT!"
|
||||
But the journal should not contain "I should not exist!"
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import os
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
from jrnl.os_compat import on_windows
|
||||
|
||||
CWD = os.getcwd()
|
||||
|
||||
|
@ -19,7 +20,7 @@ def before_feature(context, feature):
|
|||
feature.skip("Marked with @skip")
|
||||
return
|
||||
|
||||
if "skip_win" in feature.tags and "win32" in sys.platform:
|
||||
if "skip_win" in feature.tags and on_windows:
|
||||
feature.skip("Skipping on Windows")
|
||||
return
|
||||
|
||||
|
@ -46,7 +47,7 @@ def before_scenario(context, scenario):
|
|||
scenario.skip("Marked with @skip")
|
||||
return
|
||||
|
||||
if "skip_win" in scenario.effective_tags and "win32" in sys.platform:
|
||||
if "skip_win" in scenario.effective_tags and on_windows:
|
||||
scenario.skip("Skipping on Windows")
|
||||
return
|
||||
|
||||
|
|
|
@ -4,16 +4,23 @@ import os
|
|||
from pathlib import Path
|
||||
import re
|
||||
import shlex
|
||||
import sys
|
||||
import time
|
||||
from unittest.mock import patch
|
||||
|
||||
from behave import given
|
||||
from behave import then
|
||||
from behave import when
|
||||
import keyring
|
||||
import toml
|
||||
import yaml
|
||||
|
||||
from behave import given, then, when
|
||||
from jrnl import Journal, __version__, cli, install, plugins, util
|
||||
from jrnl import Journal
|
||||
from jrnl import __version__
|
||||
from jrnl import install
|
||||
from jrnl import plugins
|
||||
from jrnl.cli import cli
|
||||
from jrnl.config import load_config
|
||||
from jrnl.os_compat import on_windows
|
||||
|
||||
try:
|
||||
import parsedatetime.parsedatetime_consts as pdt
|
||||
|
@ -62,18 +69,18 @@ keyring.set_keyring(TestKeyring())
|
|||
|
||||
|
||||
def ushlex(command):
|
||||
return shlex.split(command, posix="win32" not in sys.platform)
|
||||
return shlex.split(command, posix=not on_windows)
|
||||
|
||||
|
||||
def read_journal(journal_name="default"):
|
||||
config = util.load_config(install.CONFIG_FILE_PATH)
|
||||
config = load_config(install.CONFIG_FILE_PATH)
|
||||
with open(config["journals"][journal_name]) as journal_file:
|
||||
journal = journal_file.read()
|
||||
return journal
|
||||
|
||||
|
||||
def open_journal(journal_name="default"):
|
||||
config = util.load_config(install.CONFIG_FILE_PATH)
|
||||
config = load_config(install.CONFIG_FILE_PATH)
|
||||
journal_conf = config["journals"][journal_name]
|
||||
|
||||
# We can override the default config on a by-journal basis
|
||||
|
@ -129,7 +136,7 @@ def open_editor_and_enter(context, method, text=""):
|
|||
patch("subprocess.call", side_effect=_mock_editor_function), \
|
||||
patch("sys.stdin.isatty", return_value=True) \
|
||||
:
|
||||
cli.run(["--edit"])
|
||||
cli(["--edit"])
|
||||
# fmt: on
|
||||
|
||||
|
||||
|
@ -193,7 +200,7 @@ def run_with_input(context, command, inputs=""):
|
|||
patch("sys.stdin.read", side_effect=text) as mock_read \
|
||||
:
|
||||
try:
|
||||
cli.run(args or [])
|
||||
cli(args or [])
|
||||
context.exit_status = 0
|
||||
except SystemExit as e:
|
||||
context.exit_status = e.code
|
||||
|
@ -229,7 +236,7 @@ def run(context, command, text="", cache_dir=None):
|
|||
with patch("sys.argv", args), patch(
|
||||
"subprocess.call", side_effect=_mock_editor
|
||||
), patch("sys.stdin.read", side_effect=lambda: text):
|
||||
cli.run(args[1:])
|
||||
cli(args[1:])
|
||||
context.exit_status = 0
|
||||
except SystemExit as e:
|
||||
context.exit_status = e.code
|
||||
|
@ -364,7 +371,7 @@ def config_var(context, key, value, journal=None):
|
|||
# Handle value being a dictionary
|
||||
value = ast.literal_eval(value)
|
||||
|
||||
config = util.load_config(install.CONFIG_FILE_PATH)
|
||||
config = load_config(install.CONFIG_FILE_PATH)
|
||||
if journal:
|
||||
config = config["journals"][journal]
|
||||
assert key in config
|
||||
|
@ -392,9 +399,10 @@ def list_journal_directory(context, journal="default"):
|
|||
|
||||
@then("the Python version warning should appear if our version is below {version}")
|
||||
def check_python_warning_if_version_low_enough(context, version):
|
||||
import packaging.version
|
||||
import platform
|
||||
|
||||
import packaging.version
|
||||
|
||||
if packaging.version.parse(platform.python_version()) < packaging.version.parse(
|
||||
version
|
||||
):
|
||||
|
|
|
@ -3,7 +3,8 @@ import os
|
|||
import shutil
|
||||
from xml.etree import ElementTree
|
||||
|
||||
from behave import given, then
|
||||
from behave import given
|
||||
from behave import then
|
||||
|
||||
|
||||
@then("the output should be parsable as json")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue