Update lexicon-create cli
This commit is contained in:
parent
a58761d7a5
commit
668feadda9
|
@ -1,15 +1,21 @@
|
||||||
# Standard library imports
|
# Standard library imports
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from amanuensis.cli.helpers import (
|
from amanuensis.cli.helpers import (
|
||||||
add_argument, no_argument, requires_lexicon, requires_user, alias,
|
add_argument, no_argument, requires_lexicon, requires_user, alias,
|
||||||
config_get, config_set, CONFIG_GET_ROOT_VALUE)
|
config_get, config_set, CONFIG_GET_ROOT_VALUE)
|
||||||
|
from amanuensis.config import RootConfigDirectoryContext
|
||||||
|
from amanuensis.models import LexiconModel
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
#
|
#
|
||||||
# CRUD commands
|
# CRUD commands
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
@alias('lc')
|
@alias('lc')
|
||||||
@add_argument("--name", required=True, help="The name of the new lexicon")
|
@add_argument("--name", required=True, help="The name of the new lexicon")
|
||||||
@requires_user
|
@requires_user
|
||||||
|
@ -24,22 +30,21 @@ def command_create(args):
|
||||||
opening the lexicon for player joins.
|
opening the lexicon for player joins.
|
||||||
"""
|
"""
|
||||||
# Module imports
|
# Module imports
|
||||||
from amanuensis.config import logger, json_ro
|
from amanuensis.lexicon import valid_name, create_lexicon
|
||||||
from amanuensis.lexicon.manage import valid_name, create_lexicon
|
|
||||||
|
root: RootConfigDirectoryContext = args.root
|
||||||
|
|
||||||
# Verify arguments
|
# Verify arguments
|
||||||
if not valid_name(args.name):
|
if not valid_name(args.name):
|
||||||
logger.error("Lexicon name contains illegal characters: '{}'".format(
|
logger.error(f'Lexicon name contains illegal characters: "{args.name}"')
|
||||||
args.name))
|
|
||||||
return -1
|
return -1
|
||||||
with json_ro('lexicon', 'index.json') as index:
|
with root.lexicon.read_index() as index:
|
||||||
if args.name in index.keys():
|
if args.name in index.keys():
|
||||||
logger.error('A lexicon with name "{}" already exists'.format(
|
logger.error(f'A lexicon with name "{args.name}" already exists')
|
||||||
args.name))
|
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
# Perform command
|
# Perform command
|
||||||
lexicon = create_lexicon(args.name, args.user)
|
create_lexicon(root, args.model_factory, args.name, args.user)
|
||||||
|
|
||||||
# Output already logged by create_lexicon
|
# Output already logged by create_lexicon
|
||||||
return 0
|
return 0
|
||||||
|
|
Loading…
Reference in New Issue