Add article draft create cli

This commit is contained in:
Tim Van Baak 2021-10-07 21:06:30 -07:00
parent 8754823556
commit c14959e6e6
2 changed files with 32 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import os
from typing import Callable from typing import Callable
import amanuensis.cli.admin import amanuensis.cli.admin
import amanuensis.cli.article
import amanuensis.cli.character import amanuensis.cli.character
import amanuensis.cli.index import amanuensis.cli.index
import amanuensis.cli.lexicon import amanuensis.cli.lexicon
@ -111,6 +112,7 @@ def main():
# Add commands from cli submodules # Add commands from cli submodules
subparsers = parser.add_subparsers(metavar="COMMAND") subparsers = parser.add_subparsers(metavar="COMMAND")
add_subcommand(subparsers, amanuensis.cli.admin) add_subcommand(subparsers, amanuensis.cli.admin)
add_subcommand(subparsers, amanuensis.cli.article)
add_subcommand(subparsers, amanuensis.cli.character) add_subcommand(subparsers, amanuensis.cli.character)
add_subcommand(subparsers, amanuensis.cli.index) add_subcommand(subparsers, amanuensis.cli.index)
add_subcommand(subparsers, amanuensis.cli.lexicon) add_subcommand(subparsers, amanuensis.cli.lexicon)

30
amanuensis/cli/article.py Normal file
View File

@ -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