From c14959e6e64c881f567a59e5ee77b95ae619707d Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Thu, 7 Oct 2021 21:06:30 -0700 Subject: [PATCH] Add article draft create cli --- amanuensis/cli/__init__.py | 2 ++ amanuensis/cli/article.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 amanuensis/cli/article.py diff --git a/amanuensis/cli/__init__.py b/amanuensis/cli/__init__.py index 56af06e..578fb89 100644 --- a/amanuensis/cli/__init__.py +++ b/amanuensis/cli/__init__.py @@ -5,6 +5,7 @@ import os from typing import Callable import amanuensis.cli.admin +import amanuensis.cli.article import amanuensis.cli.character import amanuensis.cli.index import amanuensis.cli.lexicon @@ -111,6 +112,7 @@ def main(): # Add commands from cli submodules subparsers = parser.add_subparsers(metavar="COMMAND") add_subcommand(subparsers, amanuensis.cli.admin) + add_subcommand(subparsers, amanuensis.cli.article) add_subcommand(subparsers, amanuensis.cli.character) add_subcommand(subparsers, amanuensis.cli.index) add_subcommand(subparsers, amanuensis.cli.lexicon) diff --git a/amanuensis/cli/article.py b/amanuensis/cli/article.py new file mode 100644 index 0000000..b81a985 --- /dev/null +++ b/amanuensis/cli/article.py @@ -0,0 +1,30 @@ +import logging + +from amanuensis.backend import * +from amanuensis.db import * + +from .helpers import add_argument + + +COMMAND_NAME = "article" +COMMAND_HELP = "Interact with articles." + +LOG = logging.getLogger(__name__) + + +@add_argument("--lexicon", required=True, help="The lexicon's name") +@add_argument("--character", required=True, help="The character's public id") +def command_create(args) -> int: + """ + Create an article in a draft state. + """ + db: DbContext = args.get_db() + lexicon = lexiq.try_from_name(db, args.lexicon) + if not lexicon: + raise ValueError("Lexicon does not exist") + char = charq.try_from_public_id(db, args.character) + if not char: + raise ValueError("Character does not exist") + article: Article = artiq.create(db, lexicon.id, char.id) + LOG.info(f"Created article {article.id} in {lexicon.full_title}") + return 0