Add article draft create cli
This commit is contained in:
parent
8754823556
commit
c14959e6e6
|
@ -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)
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue