Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/specify_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,11 @@ def version(
from .integrations._commands import register as _register_integration_cmds # noqa: E402
_register_integration_cmds(app)


# ===== Event Commands =====
from .commands.event import register as _register_event_cmds
_register_event_cmds(app)

# Re-export selected helpers to preserve the public import surface.
from .integrations._helpers import ( # noqa: E402
_clear_init_options_for_integration as _clear_init_options_for_integration,
Expand Down
36 changes: 36 additions & 0 deletions src/specify_cli/commands/event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""specify event * command handlers."""

from __future__ import annotations

from pathlib import Path
import sys
import typer

from .._console import console

event_app = typer.Typer(
name="event",
help="Manage and execute event-driven commands",
add_completion=False,
)


@event_app.command("run")
def event_run(
command_name: str = typer.Argument(..., help="Name of the command to execute"),
event_name: str = typer.Argument(..., help="Canonical event name (e.g., session_start)"),
):
"""Resolve and run an event-driven command script with stdin payload."""
from ..events import resolve_and_run_event_command

# Read payload from stdin if available
payload = sys.stdin.read() if not sys.stdin.isatty() else "{}"

# Run the event command
project_root = Path.cwd() # The agent runs events from project root
exit_code = resolve_and_run_event_command(command_name, event_name, payload, project_root)
raise typer.Exit(code=exit_code)


def register(app: typer.Typer) -> None:
app.add_typer(event_app, name="event")
8 changes: 8 additions & 0 deletions src/specify_cli/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,20 @@ def init(
if extra:
integration_parsed_options.update(extra)

from ..events import resolve_events
events_map = resolve_events(
resolved_integration.key,
resolved_integration.config,
project_path,
integration_parsed_options or None,
)
resolved_integration.setup(
project_path,
manifest,
parsed_options=integration_parsed_options or None,
script_type=selected_script,
raw_options=integration_options,
events=events_map,
)
manifest.save()

Expand Down
Loading