[cli.routes] halfapi routes --export
This commit is contained in:
parent
55878df260
commit
189fcf86f7
@ -5,18 +5,26 @@ cli/routes.py Defines the "halfapi routes" cli commands
|
||||
# builtins
|
||||
import sys
|
||||
import importlib
|
||||
from pprint import pprint
|
||||
|
||||
import click
|
||||
|
||||
from .cli import cli
|
||||
|
||||
from ..logging import logger
|
||||
|
||||
from ..lib.domain import gen_router_routes
|
||||
from ..lib.constants import DOMAIN_SCHEMA
|
||||
from ..lib.routes import api_routes
|
||||
from ..lib.schemas import schema_to_csv
|
||||
|
||||
@click.argument('module', required=True)
|
||||
@click.option('--export', default=False, is_flag=True)
|
||||
@click.option('--validate', default=False, is_flag=True)
|
||||
@click.option('--check', default=False, is_flag=True)
|
||||
@click.option('--noheader', default=False, is_flag=True)
|
||||
@cli.command()
|
||||
def routes(module, export=False, noheader=False):
|
||||
def routes(module, export=False, validate=False, check=False, noheader=False):
|
||||
"""
|
||||
The "halfapi routes" command
|
||||
"""
|
||||
@ -26,15 +34,12 @@ def routes(module, export=False, noheader=False):
|
||||
raise click.BadParameter('Cannot import this module', param=module) from exc
|
||||
|
||||
if export:
|
||||
if not noheader:
|
||||
click.echo(';'.join(('path', 'method', 'module:function', 'acl',
|
||||
'in_parameters')))
|
||||
for path, verb, m_router, fct, parameters in gen_router_routes(mod, []):
|
||||
for param in parameters:
|
||||
click.echo(';'.join((
|
||||
path,
|
||||
verb,
|
||||
f'{m_router.__name__}:{fct.__name__}',
|
||||
param['acl'].__name__,
|
||||
','.join((param.get('in', [])))
|
||||
)))
|
||||
click.echo(schema_to_csv(module, header=not noheader))
|
||||
|
||||
if validate:
|
||||
routes_d = api_routes(mod)
|
||||
try:
|
||||
DOMAIN_SCHEMA.validate(routes_d[0])
|
||||
except Exception as exc:
|
||||
pprint(routes_d[0])
|
||||
raise exc from exc
|
||||
|
Loading…
Reference in New Issue
Block a user