mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-07-07 00:36:13 +02:00
Move standalone commands into their own file
Also, cleaned up the way the arg parser handles standalone commands. Rather than checking individually for each command, you can now register the command in the proper place, and it will be run with all known arguments (and cofig if available).
This commit is contained in:
parent
5922ca41ee
commit
fb184c5f5e
4 changed files with 302 additions and 216 deletions
52
jrnl/commands.py
Normal file
52
jrnl/commands.py
Normal file
|
@ -0,0 +1,52 @@
|
|||
def deprecated_cmd(old_cmd, new_cmd, callback, **kwargs):
|
||||
import sys
|
||||
from .util import RESET_COLOR, WARNING_COLOR
|
||||
|
||||
print(
|
||||
WARNING_COLOR,
|
||||
f"\nThe command {old_cmd} is deprecated and will be removed from jrnl soon.\n"
|
||||
f"Please use {new_cmd} instead.\n",
|
||||
RESET_COLOR,
|
||||
file=sys.stderr,
|
||||
)
|
||||
callback(**kwargs)
|
||||
|
||||
|
||||
def preconfig_diagnostic(_):
|
||||
import platform
|
||||
import sys
|
||||
import jrnl
|
||||
|
||||
print(
|
||||
f"jrnl: {jrnl.__version__}\n"
|
||||
f"Python: {sys.version}\n"
|
||||
f"OS: {platform.system()} {platform.release()}"
|
||||
)
|
||||
|
||||
|
||||
def preconfig_version(_):
|
||||
import jrnl
|
||||
|
||||
version_str = f"{jrnl.__title__} version {jrnl.__version__}"
|
||||
print(version_str)
|
||||
|
||||
|
||||
def preconfig_command(args):
|
||||
print("this is a pre-config command")
|
||||
|
||||
|
||||
def postconfig_list(config, **kwargs):
|
||||
print(list_journals(config))
|
||||
|
||||
|
||||
def list_journals(config):
|
||||
from . import install
|
||||
|
||||
"""List the journals specified in the configuration file"""
|
||||
result = f"Journals defined in {install.CONFIG_FILE_PATH}\n"
|
||||
ml = min(max(len(k) for k in config["journals"]), 20)
|
||||
for journal, cfg in config["journals"].items():
|
||||
result += " * {:{}} -> {}\n".format(
|
||||
journal, ml, cfg["journal"] if isinstance(cfg, dict) else cfg
|
||||
)
|
||||
return result
|
Loading…
Add table
Add a link
Reference in a new issue