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:
Jonathan Wren 2020-08-22 11:40:39 -07:00 committed by GitHub
parent 7c3abb2625
commit 631e08a557
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 981 additions and 775 deletions

View file

@ -8,10 +8,15 @@ import sys
import xdg.BaseDirectory
import yaml
from . import __version__, util
from .util import UserAbort, verify_config
from . import __version__
from .config import load_config
from .config import verify_config_colors
from .exception import UserAbort
from .os_compat import on_windows
from .prompt import yesno
from .upgrade import is_old_version
if "win32" not in sys.platform:
if not on_windows:
# readline is not included in Windows Active Python
import readline
@ -29,18 +34,6 @@ CONFIG_FILE_PATH_FALLBACK = os.path.join(USER_HOME, ".jrnl_config")
JOURNAL_PATH = xdg.BaseDirectory.save_data_path(XDG_RESOURCE) or USER_HOME
JOURNAL_FILE_PATH = os.path.join(JOURNAL_PATH, DEFAULT_JOURNAL_NAME)
log = logging.getLogger(__name__)
def module_exists(module_name):
"""Checks if a module exists and can be imported"""
try:
__import__(module_name)
except ImportError:
return False
else:
return True
default_config = {
"version": __version__,
@ -93,10 +86,10 @@ def load_or_install_jrnl():
else CONFIG_FILE_PATH_FALLBACK
)
if os.path.exists(config_path):
log.debug("Reading configuration from file %s", config_path)
config = util.load_config(config_path)
logging.debug("Reading configuration from file %s", config_path)
config = load_config(config_path)
if util.is_old_version(config_path):
if is_old_version(config_path):
from . import upgrade
try:
@ -115,24 +108,24 @@ def load_or_install_jrnl():
sys.exit(1)
upgrade_config(config)
verify_config(config)
verify_config_colors(config)
else:
log.debug("Configuration file not found, installing jrnl...")
logging.debug("Configuration file not found, installing jrnl...")
try:
config = install()
except KeyboardInterrupt:
raise UserAbort("Installation aborted")
log.debug('Using configuration "%s"', config)
logging.debug('Using configuration "%s"', config)
return config
def install():
if "win32" not in sys.platform:
if not on_windows:
readline.set_completer_delims(" \t\n;")
readline.parse_and_bind("tab: complete")
readline.set_completer(autocomplete)
readline.set_completer(_autocomplete_path)
# Where to create the journal?
path_query = f"Path to your journal file (leave blank for {JOURNAL_FILE_PATH}): "
@ -149,7 +142,7 @@ def install():
pass
# Encrypt it?
encrypt = util.yesno(
encrypt = yesno(
"Do you want to encrypt your journal? You can always change this later",
default=False,
)
@ -161,7 +154,7 @@ def install():
return default_config
def autocomplete(text, state):
def _autocomplete_path(text, state):
expansions = glob.glob(os.path.expanduser(os.path.expandvars(text)) + "*")
expansions = [e + "/" if os.path.isdir(e) else e for e in expansions]
expansions.append(None)