mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-17 11:38:32 +02:00
add type hints
This commit is contained in:
parent
ceefc0cfce
commit
3d207d7076
2 changed files with 22 additions and 7 deletions
|
@ -14,6 +14,7 @@ run.
|
||||||
Also, please note that all (non-builtin) imports should be scoped to each function to
|
Also, please note that all (non-builtin) imports should be scoped to each function to
|
||||||
avoid any possible overhead for these standalone commands.
|
avoid any possible overhead for these standalone commands.
|
||||||
"""
|
"""
|
||||||
|
import argparse
|
||||||
import platform
|
import platform
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -57,14 +58,16 @@ def preconfig_version(_):
|
||||||
print(output)
|
print(output)
|
||||||
|
|
||||||
|
|
||||||
def postconfig_list(args, config, **_):
|
def postconfig_list(args: argparse.Namespace, config: dict, **_) -> int:
|
||||||
from jrnl.output import list_journals
|
from jrnl.output import list_journals
|
||||||
|
|
||||||
print(list_journals(config, args.export))
|
print(list_journals(config, args.export))
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
@cmd_requires_valid_journal_name
|
@cmd_requires_valid_journal_name
|
||||||
def postconfig_import(args, config, **_):
|
def postconfig_import(args: argparse.Namespace, config: dict, **_) -> int:
|
||||||
from jrnl.Journal import open_journal
|
from jrnl.Journal import open_journal
|
||||||
from jrnl.plugins import get_importer
|
from jrnl.plugins import get_importer
|
||||||
|
|
||||||
|
@ -74,9 +77,13 @@ def postconfig_import(args, config, **_):
|
||||||
format = args.export if args.export else "jrnl"
|
format = args.export if args.export else "jrnl"
|
||||||
get_importer(format).import_(journal, args.filename)
|
get_importer(format).import_(journal, args.filename)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
@cmd_requires_valid_journal_name
|
@cmd_requires_valid_journal_name
|
||||||
def postconfig_encrypt(args, config, original_config, **_):
|
def postconfig_encrypt(
|
||||||
|
args: argparse.Namespace, config: dict, original_config: dict
|
||||||
|
) -> int:
|
||||||
"""
|
"""
|
||||||
Encrypt a journal in place, or optionally to a new file
|
Encrypt a journal in place, or optionally to a new file
|
||||||
"""
|
"""
|
||||||
|
@ -125,9 +132,13 @@ def postconfig_encrypt(args, config, original_config, **_):
|
||||||
)
|
)
|
||||||
save_config(original_config)
|
save_config(original_config)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
@cmd_requires_valid_journal_name
|
@cmd_requires_valid_journal_name
|
||||||
def postconfig_decrypt(args, config, original_config, **kwargs):
|
def postconfig_decrypt(
|
||||||
|
args: argparse.Namespace, config: dict, original_config: dict
|
||||||
|
) -> int:
|
||||||
"""Decrypts into new file. If filename is not set, we encrypt the journal file itself."""
|
"""Decrypts into new file. If filename is not set, we encrypt the journal file itself."""
|
||||||
from jrnl.config import update_config
|
from jrnl.config import update_config
|
||||||
from jrnl.install import save_config
|
from jrnl.install import save_config
|
||||||
|
@ -153,3 +164,5 @@ def postconfig_decrypt(args, config, original_config, **kwargs):
|
||||||
original_config, {"encrypt": False}, args.journal_name, force_local=True
|
original_config, {"encrypt": False}, args.journal_name, force_local=True
|
||||||
)
|
)
|
||||||
save_config(original_config)
|
save_config(original_config)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
# Copyright © 2012-2022 jrnl contributors
|
# Copyright © 2012-2022 jrnl contributors
|
||||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||||
|
|
||||||
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
from typing import Callable
|
||||||
|
|
||||||
import colorama
|
import colorama
|
||||||
import xdg.BaseDirectory
|
import xdg.BaseDirectory
|
||||||
|
@ -217,15 +219,15 @@ def get_journal_name(args, config):
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
def cmd_requires_valid_journal_name(func):
|
def cmd_requires_valid_journal_name(func: Callable) -> Callable:
|
||||||
def wrapper(args, config, original_config):
|
def wrapper(args: argparse.Namespace, config: dict, original_config: dict):
|
||||||
validate_journal_name(args.journal_name, config)
|
validate_journal_name(args.journal_name, config)
|
||||||
func(args=args, config=config, original_config=original_config)
|
func(args=args, config=config, original_config=original_config)
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
def validate_journal_name(journal_name, config):
|
def validate_journal_name(journal_name: str, config: dict) -> None:
|
||||||
if journal_name not in config["journals"]:
|
if journal_name not in config["journals"]:
|
||||||
raise JrnlException(
|
raise JrnlException(
|
||||||
Message(
|
Message(
|
||||||
|
|
Loading…
Add table
Reference in a new issue