"""GFINDER CLI `geometries` command."""
import click
from .docstring import set_docstring
from gfinder.geometry import GeometryFactory
@click.command(name='geometries')
@click.option('-name', '--name-filter', type=click.STRING, help='Filter by any string contained in the Geometry class name.')
@click.option('-class', '--class-filter', type=click.STRING, help='Filter by Geometry parent class (eg: Scalar, Direction)')
@click.option('--searchable/--no-searchable', help='Show source code for computing Geometry.', default='False')
def geometries_cmd(name_filter, class_filter, searchable):
"""List available geometry classes.
"""
geometries(name_filter=name_filter, class_filter=class_filter, searchable=searchable)
[docs]@set_docstring(geometries_cmd)
def geometries(name_filter=None, class_filter=None, searchable=None):
# Retrieve list of available Geometry classes
geometry_factory = GeometryFactory()
geometry_class_names = geometry_factory.get_geometries(name_filter=name_filter, class_filter=class_filter, searchable=searchable)
n_classes = len(geometry_class_names)
# Determine maximum length of available Geometry classes names, for formatting.
max_name_length = 0
for geometry_class_name in geometry_class_names:
if len(geometry_class_name) > max_name_length:
max_name_length = len(geometry_class_name)
if n_classes > 0:
if n_classes == 1:
click.echo('One Geometry class matching input filter:')
else:
click.echo(f'{n_classes} Geometry classes matching input filter:')
click.echo()
for geometry_class_name in geometry_class_names:
geometry_class_dict = geometry_factory.get_geometry_info(geometry_class_name)
click.echo(f' {geometry_class_name+" ("+geometry_class_dict["parent_class"]+")":<{max_name_length+18}} {geometry_class_dict["short_description"]}')
else:
click.echo(f'No Geometry classes matching input filter.')
click.echo()