mirror of
https://github.com/aljazceru/goose.git
synced 2025-12-27 02:54:23 +01:00
feat: add version options (#74)
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user