feat: add version options (#74)
This commit is contained in:
+11
-6
@@ -1,6 +1,6 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict, Optional
|
from typing import Optional
|
||||||
|
|
||||||
import click
|
import click
|
||||||
from rich import print
|
from rich import print
|
||||||
@@ -17,8 +17,8 @@ def goose_cli() -> None:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@goose_cli.command()
|
@goose_cli.command(name="version")
|
||||||
def version() -> None:
|
def get_version() -> None:
|
||||||
"""Lists the version of goose and any plugins"""
|
"""Lists the version of goose and any plugins"""
|
||||||
from importlib.metadata import entry_points, version
|
from importlib.metadata import entry_points, version
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ def session_clear(keep: int) -> None:
|
|||||||
session_file.unlink()
|
session_file.unlink()
|
||||||
|
|
||||||
|
|
||||||
def get_session_files() -> Dict[str, Path]:
|
def get_session_files() -> dict[str, Path]:
|
||||||
return list_sorted_session_files(SESSIONS_PATH)
|
return list_sorted_session_files(SESSIONS_PATH)
|
||||||
|
|
||||||
|
|
||||||
@@ -121,9 +121,14 @@ def get_session_files() -> Dict[str, Path]:
|
|||||||
name="goose",
|
name="goose",
|
||||||
help="AI-powered tool to assist in solving programming and operational tasks",
|
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
|
@click.pass_context
|
||||||
def cli(_: click.Context, **kwargs: Dict) -> None:
|
def cli(ctx: click.Context, version: bool, **kwargs: dict) -> None:
|
||||||
pass
|
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")
|
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"])
|
runner.invoke(cli, ["session", "resume", "session1", "--profile", "default"])
|
||||||
mock_session_class.assert_called_once_with(name="session1", profile="default")
|
mock_session_class.assert_called_once_with(name="session1", profile="default")
|
||||||
mock_session_instance.run.assert_called_once()
|
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