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 20, 2024
1 parent 238c86f commit 131e010
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/goose/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,36 @@ 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"""
session_files = get_session_files()
if name is None:
session_files = get_session_files()
if session_files:
name = list(session_files.keys())[0]
print(f"Resuming most recent session: {name} from {session_files[name]}")
else:
print("No sessions found.")
return
else:
if name in session_files:
print(f"Resuming session: {name}")
else:
print(f"Creating new session: {name}")
session = Session(name=name, profile=profile)
session.run()

Expand All @@ -146,10 +163,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 131e010

Please sign in to comment.