Skip to content

Commit

Permalink
Add version command to CLI (#348)
Browse files Browse the repository at this point in the history
* feat: add version command to cli with tools flag

* test: check output of version and tools flag

* fix: add version tool info to cli outputs
  • Loading branch information
whoabuddy committed May 15, 2024
1 parent 1e112fa commit 208c3a7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/crewai/cli/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import click
import pkg_resources

from .create_crew import create_crew

Expand All @@ -15,5 +16,22 @@ def create(project_name):
create_crew(project_name)


@crewai.command()
@click.option(
"--tools", is_flag=True, help="Show the installed version of crewai tools"
)
def version(tools):
"""Show the installed version of crewai."""
crewai_version = pkg_resources.get_distribution("crewai").version
click.echo(f"crewai version: {crewai_version}")

if tools:
try:
tools_version = pkg_resources.get_distribution("crewai[tools]").version
click.echo(f"crewai tools version: {tools_version}")
except pkg_resources.DistributionNotFound:
click.echo("crewai tools not installed")


if __name__ == "__main__":
crewai()
20 changes: 20 additions & 0 deletions tests/cli_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from click.testing import CliRunner
from crewai.cli.cli import version


def test_version_command():
runner = CliRunner()
result = runner.invoke(version)
assert result.exit_code == 0
assert "crewai version:" in result.output


def test_version_command_with_tools():
runner = CliRunner()
result = runner.invoke(version, ["--tools"])
assert result.exit_code == 0
assert "crewai version:" in result.output
assert (
"crewai tools version:" in result.output
or "crewai tools not installed" in result.output
)

0 comments on commit 208c3a7

Please sign in to comment.