Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/apighost/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""APIGhost CLI entry point OpenAPI spec to mock server."""
"""APIGhost CLI entry point - OpenAPI spec to mock server."""

from __future__ import annotations

Expand Down Expand Up @@ -59,7 +59,7 @@ def serve(spec, port, host, scenario, record, cassette_name, latency, watch):
apighost serve spec.yaml --scenario error_400
apighost serve spec.yaml --record --cassette-name my-test
"""
click.echo(f" APIGhost v{__version__} loading spec...")
click.echo(f" APIGhost v{__version__} - loading spec...")
click.echo(f" Spec: {spec}")

try:
Expand Down Expand Up @@ -113,10 +113,10 @@ def serve(spec, port, host, scenario, record, cassette_name, latency, watch):


def _on_shutdown(recorder, cassette_name, spec_path):
"""Handle server shutdown save cassette if recording."""
"""Handle server shutdown - save cassette if recording."""
if recorder and recorder.count > 0:
path = recorder.save(cassette_name or f"recording-{int(time.time())}", spec_path)
click.echo(f"\n Recorded {recorder.count} interactions → {path}")
click.echo(f"\n Recorded {recorder.count} interactions {path}")
click.echo("\n Server stopped.")


Expand Down Expand Up @@ -169,14 +169,14 @@ def record(spec, output, port, requests):
click.echo(f" {ep.method:>6} {resp.status_code} {filled_path}")
count += 1
except Exception as e:
click.echo(f" {ep.method:>6} ERROR {filled_path} {e}")
click.echo(f" {ep.method:>6} ERROR {filled_path} - {e}")

# Determine output
if not output:
output = f"cassette-{api_spec.title.replace(' ', '-').lower()}-{int(time.time())}"

path = recorder.save(output, spec)
click.echo(f"\n Recorded {recorder.count} interactions → {path}")
click.echo(f"\n Recorded {recorder.count} interactions {path}")
return path


Expand All @@ -196,7 +196,7 @@ def replay(cassette, port, host):
click.echo(f" Error: {e}", err=True)
sys.exit(1)

click.echo(f" APIGhost replaying cassette: {cassette_data.name}")
click.echo(f" APIGhost - replaying cassette: {cassette_data.name}")
click.echo(f" Interactions: {len(cassette_data.interactions)}")
if cassette_data.spec_path:
click.echo(f" Original spec: {cassette_data.spec_path}")
Expand Down Expand Up @@ -224,7 +224,7 @@ def _replay_handler(path):
@app.route("/")
def _replay_home():
return jsonify({
"service": f"APIGhost Replay {cassette_data.name}",
"service": f"APIGhost Replay - {cassette_data.name}",
"interactions": len(cassette_data.interactions),
"endpoints": list(set(f"{i.request_method} {i.request_path}"
for i in cassette_data.interactions)),
Expand Down Expand Up @@ -275,7 +275,7 @@ def cassette_info(name):
click.echo()
for i, interaction in enumerate(data.interactions, 1):
click.echo(f" {i}. {interaction.request_method} {interaction.request_path}")
click.echo(f" → {interaction.response_status}")
click.echo(f" {interaction.response_status}")


@cli.group()
Expand Down Expand Up @@ -303,7 +303,7 @@ def scenario_list():
def scenario_create(name, description):
"""Create a new empty scenario."""
path = save_scenario(name, description)
click.echo(f" Created scenario '{name}' → {path}")
click.echo(f" Created scenario '{name}' {path}")


@scenario.command("edit")
Expand Down Expand Up @@ -331,7 +331,7 @@ def scenario_edit(name, route, status, body):

sc.overrides[route] = {"status": status, "body": parsed_body}
save_scenario(sc.name, sc.description, sc.overrides)
click.echo(f" Updated scenario '{name}' overrides: {len(sc.overrides)}")
click.echo(f" Updated scenario '{name}' - overrides: {len(sc.overrides)}")


@scenario.command("delete")
Expand Down Expand Up @@ -366,7 +366,7 @@ def generate(spec, output, name):
click.echo(f" {ep.method:<6} {ep.path}")

path = save_scenario(scenario_name, f"Auto-generated from {spec}", overrides)
click.echo(f"\n Generated {len(overrides)} endpoint responses → {path}")
click.echo(f"\n Generated {len(overrides)} endpoint responses {path}")


@cli.command()
Expand Down
Loading