Fix bug for new --list --format options when no default journal is specified (#1621)

* rename test config

* Change journal name validation

Journal name validation used to happen before postconfig commands could
have a chance to run, so now each command is responsible for its own
error-checking of the journal name.

Added a new decorator and function that makes this error-checking easier.

Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>

* fix wrapper function call to be more like original

* change arg names to show which aren't used

* add type hints

Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
This commit is contained in:
Jonathan Wren 2022-10-22 15:35:16 -07:00 committed by GitHub
parent 619de775fd
commit 63850a33c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 70 additions and 19 deletions

View file

@ -1,8 +1,10 @@
# Copyright © 2012-2022 jrnl contributors
# License: https://www.gnu.org/licenses/gpl-3.0.html
import argparse
import logging
import os
from typing import Callable
import colorama
import xdg.BaseDirectory
@ -213,14 +215,27 @@ def get_journal_name(args, config):
args.journal_name = potential_journal_name
args.text = args.text[1:]
if args.journal_name not in config["journals"]:
raise JrnlException(
Message(
MsgText.NoDefaultJournal,
MsgStyle.ERROR,
{"journals": list_journals(config)},
),
)
logging.debug("Using journal name: %s", args.journal_name)
return args
def cmd_requires_valid_journal_name(func: Callable) -> Callable:
def wrapper(args: argparse.Namespace, config: dict, original_config: dict):
validate_journal_name(args.journal_name, config)
func(args=args, config=config, original_config=original_config)
return wrapper
def validate_journal_name(journal_name: str, config: dict) -> None:
if journal_name not in config["journals"]:
raise JrnlException(
Message(
MsgText.NoNamedJournal,
MsgStyle.ERROR,
{
"journal_name": journal_name,
"journals": list_journals(config),
},
),
)