Skip to content

Commit

Permalink
feature: Debug command for environments
Browse files Browse the repository at this point in the history
  • Loading branch information
antonagestam committed Oct 19, 2024
1 parent 87935de commit 7d9890d
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/goose/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@
from rich.text import Text

from goose.backend.base import RunResult
from goose.config import EnvironmentId
from goose.config import HookConfig

from .asyncio import asyncio_entrypoint
from .context import gather_context
from .environment import Environment
from .environment import InitialState
from .environment import NeedsFreeze
from .environment import SyncedState
from .environment import UninitializedState
from .environment import prepare_environment
from .orphan_environments import probe_orphan_environments
from .scheduler import Scheduler
Expand Down Expand Up @@ -222,6 +227,52 @@ async def run(
print_summary(console, scheduler)


@cli.command()
@asyncio_entrypoint
async def environment(
selected_environment: Optional[str] = typer.Argument(default=None), # noqa
config_path: ConfigOption = default_config,
) -> None:
console = Console()
error_console = Console(stderr=True)
ctx = gather_context(config_path)

def print_environment(environment: Environment) -> None:
console.print(f"{environment.config.id}")
console.print(f" config.ecosystem: {environment.config.ecosystem}")
console.print(f" path: {environment._path}")
console.print(f" lock-files-path: {environment.lock_files_path}")

state = environment.state
if isinstance(state, UninitializedState):
console.print(" state: uninitialized")
elif isinstance(state, InitialState):
console.print(" state: initial")
console.print(f" state.stage: {state.stage.value}")
console.print(f" state.ecosystem: {state.ecosystem}")
elif isinstance(state, SyncedState):
console.print(" state: synced")
console.print(f" state.stage: {state.stage.value}")
console.print(f" state.ecosystem: {state.ecosystem}")
console.print(f" state.checksum: {state.checksum!r}")

else:
assert_never(state)

if selected_environment is None:
for environment in ctx.environments.values():
print_environment(environment)
return

try:
environment = ctx.environments[EnvironmentId(selected_environment)]
except KeyError:
error_console.print("No such environment")
raise SystemExit(1) from None

print_environment(environment)


@cli.command()
@asyncio_entrypoint
async def select(
Expand Down

0 comments on commit 7d9890d

Please sign in to comment.