"""GFINDER CLI `events` command."""
import click
from .docstring import set_docstring
from gfinder.config import Config
from gfinder.datastore import DataStore
@click.command(name='events')
@click.option('--event-file-key', type=click.STRING, help='Filter by event file key (eg: "phase", "orbit")')
@click.option('--filter', type=click.STRING, help='Filter name using complex regular expression.')
@click.option('--before', type=click.STRING, help='Filter before a given UTC time.')
@click.option('--after', type=click.STRING, help='Filter after a given UTC time.')
@click.option('--mission-scenario-id', type=click.STRING, help='Mission scenario ID (default: '+Config().default_mission_scenario_id+')')
def events_cmd(event_file_key, filter, before, after, mission_scenario_id):
"""List mission events for a given mission scenario.
Examples:
\b
gfinder events --event-file-key=phase --mission-scenario-id=CREMA5_1_150lb
gfinder events --filter='flyby'
"""
events(event_file_key=event_file_key, filter=filter, before=before, after=after, mission_scenario_id=mission_scenario_id)
[docs]@set_docstring(events_cmd)
def events(event_file_key='', filter=None, before=None, after=None, mission_scenario_id=None):
# Init data store
datastore = DataStore()
# Get selected mission scenario
if not mission_scenario_id:
mission_scenario_id = Config().default_mission_scenario_id
mission_scenario = datastore.getMissionScenario(mission_scenario_id)
if not mission_scenario:
print(f'Invalid {mission_scenario_id} mission scenario. Use `scenarios` command to list available mission'
f'scenarios, defined scenarios/mission_scenarios.json file.')
return
mission_event_ids = mission_scenario.get_events_ids(event_file_key=event_file_key, filter=filter, before=before, after=after)
click.echo()
click.echo(f'Mission events for {mission_scenario.id} mission scenario matching input filter:')
click.echo(mission_event_ids)
click.echo()