Skip to content

Commit

Permalink
Show sgpt version command line option (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
Navidur1 authored Dec 12, 2023
1 parent f3413c0 commit e61caf5
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ dev = [
]

[tool.hatch.version]
path = "sgpt/__init__.py"
path = "sgpt/__version__.py"

[tool.hatch.build.targets.wheel]
only-include = ["sgpt"]
Expand Down
2 changes: 0 additions & 2 deletions sgpt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
from .app import main as main
from .app import entry_point as cli # noqa: F401

__version__ = "0.9.4"
1 change: 1 addition & 0 deletions sgpt/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.9.4"
14 changes: 13 additions & 1 deletion sgpt/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
from sgpt.handlers.default_handler import DefaultHandler
from sgpt.handlers.repl_handler import ReplHandler
from sgpt.role import DefaultRoles, SystemRole
from sgpt.utils import get_edited_prompt, install_shell_integration, run_command
from sgpt.utils import (
get_edited_prompt,
get_sgpt_version,
install_shell_integration,
run_command,
)


def main(
Expand Down Expand Up @@ -63,6 +68,13 @@ def main(
True,
help="Cache completion results.",
),
version: bool = typer.Option(
False,
"--version",
"-v",
help="Show version.",
callback=get_sgpt_version,
),
chat: str = typer.Option(
None,
help="Follow conversation with id, " 'use "temp" for quick session.',
Expand Down
10 changes: 10 additions & 0 deletions sgpt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import typer
from click import BadParameter

from sgpt.__version__ import __version__


def get_edited_prompt() -> str:
"""
Expand Down Expand Up @@ -74,3 +76,11 @@ def install_shell_integration(*_args: Any) -> None:
else:
url = "https://raw.githubusercontent.com/TheR1D/shell_gpt/shell-integrations/install.sh"
os.system(f'sh -c "$(curl -fsSL {url})"')


@option_callback
def get_sgpt_version(*_args: Any) -> None:
"""
Displays the current installed version of ShellGPT
"""
typer.echo(f"ShellGPT {__version__}")
17 changes: 17 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import typer
from typer.testing import CliRunner

from sgpt.__version__ import __version__
from sgpt.app import main
from sgpt.config import cfg
from sgpt.handlers.handler import Handler
Expand Down Expand Up @@ -454,3 +455,19 @@ def test_shell_command_run_description(self):
# Can't really test it since stdin in disable for --shell flag.
# for word in ("prints", "hello", "console"):
# assert word in result.stdout

def test_version(self):
dict_arguments = {
"prompt": "",
"--version": True,
}
result = runner.invoke(app, self.get_arguments(**dict_arguments), input="d\n")
assert __version__ in result.stdout

dict_arguments = {
"prompt": "",
"-v": True,
}

result = runner.invoke(app, self.get_arguments(**dict_arguments), input="d\n")
assert __version__ in result.stdout

0 comments on commit e61caf5

Please sign in to comment.