Skip to content

Commit

Permalink
feat: add autocomplete for session files
Browse files Browse the repository at this point in the history
  • Loading branch information
lamchau committed Sep 18, 2024
1 parent bfd19f3 commit 811ed30
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/goose/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,26 @@ def session_start(profile: str, plan: Optional[str] = None) -> None:
session.run()


def autocomplete_session_files(ctx: click.Context, args: str, incomplete: str) -> None:
return [
f"{session_name}"
for session_name in sorted(get_session_files().keys(), reverse=True, key=lambda x: x.lower())
if session_name.startswith(incomplete)
]


def get_session_files() -> Dict[str, Path]:
return list_sorted_session_files(SESSIONS_PATH)


@session.command(name="resume")
@click.argument("name", required=False)
@click.argument("name", required=False, shell_complete=autocomplete_session_files)
@click.option("--profile")
def session_resume(name: Optional[str], profile: str) -> None:
"""Resume an existing goose session"""
if name is not None:
click.echo(f"Resuming session: {name}")

if name is None:
session_files = get_session_files()
if session_files:
Expand Down Expand Up @@ -132,10 +147,6 @@ def session_clear(keep: int) -> None:
session_file.unlink()


def get_session_files() -> Dict[str, Path]:
return list_sorted_session_files(SESSIONS_PATH)


@click.group(
invoke_without_command=True,
name="goose",
Expand Down

0 comments on commit 811ed30

Please sign in to comment.