Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add version options #74

Merged
merged 4 commits into from
Sep 19, 2024
Merged
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
17 changes: 11 additions & 6 deletions src/goose/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime
from pathlib import Path
from typing import Dict, Optional
from typing import Optional

import click
from rich import print
Expand All @@ -17,8 +17,8 @@ def goose_cli() -> None:
pass


@goose_cli.command()
def version() -> None:
@goose_cli.command(name="version")
def get_version() -> None:
"""Lists the version of goose and any plugins"""
from importlib.metadata import entry_points, version

Expand Down Expand Up @@ -112,7 +112,7 @@ def session_clear(keep: int) -> None:
session_file.unlink()


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


Expand All @@ -121,9 +121,14 @@ def get_session_files() -> Dict[str, Path]:
name="goose",
help="AI-powered tool to assist in solving programming and operational tasks",
)
@click.option("-V", "--version", is_flag=True, help="List the version of goose and any plugins")
@click.pass_context
def cli(_: click.Context, **kwargs: Dict) -> None:
pass
def cli(ctx: click.Context, version: bool, **kwargs: dict) -> None:
if version:
ctx.invoke(get_version)
ctx.exit()
elif ctx.invoked_subcommand is None:
click.echo(ctx.get_help())


all_cli_group_options = load_plugins("goose.cli.group_option")
Expand Down
30 changes: 30 additions & 0 deletions tests/cli/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,33 @@ def test_combined_group_commands(mock_session):
runner.invoke(cli, ["session", "resume", "session1", "--profile", "default"])
mock_session_class.assert_called_once_with(name="session1", profile="default")
mock_session_instance.run.assert_called_once()


def test_version_long_option():
runner = CliRunner()
result = runner.invoke(cli, ["--version"])
assert result.exit_code == 0
assert "version" in result.output.lower()


def test_version_short_option():
runner = CliRunner()
result = runner.invoke(cli, ["-V"])
assert result.exit_code == 0
assert "version" in result.output.lower()


def test_version_subcommand():
runner = CliRunner()
result = runner.invoke(cli, ["version"])
assert result.exit_code == 0
assert "version" in result.output.lower()


def test_goose_no_args_print_help():
runner = CliRunner()
result = runner.invoke(cli, [])
assert result.exit_code == 0
assert "Usage:" in result.output
assert "Options:" in result.output
assert "Commands:" in result.output