[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
|
# builtins
|
||||||
import sys
|
import sys
|
||||||
import importlib
|
import importlib
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from .cli import cli
|
from .cli import cli
|
||||||
|
|
||||||
|
from ..logging import logger
|
||||||
|
|
||||||
from ..lib.domain import gen_router_routes
|
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.argument('module', required=True)
|
||||||
@click.option('--export', default=False, is_flag=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)
|
@click.option('--noheader', default=False, is_flag=True)
|
||||||
@cli.command()
|
@cli.command()
|
||||||
def routes(module, export=False, noheader=False):
|
def routes(module, export=False, validate=False, check=False, noheader=False):
|
||||||
"""
|
"""
|
||||||
The "halfapi routes" command
|
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
|
raise click.BadParameter('Cannot import this module', param=module) from exc
|
||||||
|
|
||||||
if export:
|
if export:
|
||||||
if not noheader:
|
click.echo(schema_to_csv(module, header=not noheader))
|
||||||
click.echo(';'.join(('path', 'method', 'module:function', 'acl',
|
|
||||||
'in_parameters')))
|
if validate:
|
||||||
for path, verb, m_router, fct, parameters in gen_router_routes(mod, []):
|
routes_d = api_routes(mod)
|
||||||
for param in parameters:
|
try:
|
||||||
click.echo(';'.join((
|
DOMAIN_SCHEMA.validate(routes_d[0])
|
||||||
path,
|
except Exception as exc:
|
||||||
verb,
|
pprint(routes_d[0])
|
||||||
f'{m_router.__name__}:{fct.__name__}',
|
raise exc from exc
|
||||||
param['acl'].__name__,
|
|
||||||
','.join((param.get('in', [])))
|
|
||||||
)))
|
|
||||||
|
Loading…
Reference in New Issue
Block a user