Skip to content

Comments

feat: add --version/-v flag to CLI#355

Open
teamauresta wants to merge 1 commit intovitali87:mainfrom
teamauresta:feat/add-version-command
Open

feat: add --version/-v flag to CLI#355
teamauresta wants to merge 1 commit intovitali87:mainfrom
teamauresta:feat/add-version-command

Conversation

@teamauresta
Copy link

@teamauresta teamauresta commented Feb 22, 2026

Implements cgr --version and cgr -v commands that display the current package version read from importlib.metadata.

Acceptance criteria from issue #239:

  • cgr --version and cgr -v both work
  • Version read from package metadata (not hardcoded)
  • Output format: code-graph-rag version X.Y.Z

Test: added test_version_flag() to test_cli_smoke.py (subprocess pattern)

Summary

Type of Change

  • Bug fix
  • New feature
  • Performance improvement
  • Refactoring (no functional changes)
  • Documentation
  • CI/CD or tooling
  • Dependencies

Related Issues

Test Plan

  • Unit tests pass (make test-parallel or uv run pytest -n auto -m "not integration")
  • New tests added
  • Integration tests pass (make test-integration, requires Docker)
  • Manual testing (describe below)

Checklist

  • PR title follows Conventional Commits format
  • All pre-commit checks pass (make pre-commit)
  • No hardcoded strings in non-config/non-constants files
  • No # type: ignore, cast(), Any, or object type hints
  • No new comments or docstrings (code should be self-documenting)

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @teamauresta, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the command-line interface by introducing a standard --version and -v flag. This allows users to easily query the installed application's version, improving user experience and simplifying debugging. The implementation ensures the version information is always accurate by fetching it directly from the package metadata rather than relying on hardcoded values.

Highlights

  • CLI Version Flag: Implemented --version and -v flags for the cgr command-line interface to display the current package version.
  • Dynamic Version Retrieval: The version is now dynamically retrieved from importlib.metadata, ensuring it's always up-to-date with the installed package.
  • New Test Coverage: Added test_version_flag() to test_cli_smoke.py to verify the correct behavior and output of the new version flags.
Changelog
  • codebase_rag/cli.py
    • Imported get_version from importlib.metadata.
    • Added _version_callback function to retrieve and display the package version.
    • Integrated --version and -v options into the global CLI callback, using _version_callback.
  • codebase_rag/tests/test_cli_smoke.py
    • Added test_version_flag to test the --version and -v CLI flags, verifying correct output and exit behavior.
Activity
  • No human activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces a new feature to display the application version via --version or -v flags, which is a good addition for user convenience and debugging. The implementation correctly uses importlib.metadata.version to retrieve the package version, ensuring it's not hardcoded. A dedicated test case has been added to verify the functionality of the new flags, which is crucial for maintaining code quality. The use of typer.Exit() after displaying the version is appropriate to terminate the application gracefully. Overall, the changes are well-implemented and align with the stated acceptance criteria.

assert result.stdout.startswith("code-graph-rag version "), (
f"{flag} output did not match expected format: {repr(result.stdout)}"
)
assert result.stderr == "", f"Unexpected stderr for {flag}: {result.stderr}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The assertion assert result.stderr == "", f"Unexpected stderr for {flag}: {result.stderr}" is good for ensuring clean output. However, in some environments, typer.echo might write to stderr instead of stdout depending on how the output stream is configured or redirected. While typer.echo typically writes to stdout, it's safer to check if stderr is empty or contains only expected output, especially when dealing with CLI tools that might have subtle differences in output streams across platforms or configurations. For this specific case, since typer.echo is used, it's highly probable it will write to stdout, but it's a good practice to be aware of this potential edge case.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 23, 2026

Greptile Summary

Implements --version and -v flags that display the package version from importlib.metadata, fulfilling the acceptance criteria from issue #239.

  • Added _version_callback function to handle version display
  • Registered version option in _global_options callback with is_eager=True to execute before other commands
  • Test coverage validates both --version and -v flags work correctly

Issues found:

  • Hardcoded strings violate the "No Hardcoded Strings" policy - need to move help text to cli_help.py and version format string to constants.py
  • Uses typer.echo() instead of app_context.console.print() per coding standards

Confidence Score: 3/5

  • Safe to merge after addressing hardcoded string violations
  • Implementation is functionally correct and well-tested, but violates project coding standards by using hardcoded strings instead of constants and typer.echo() instead of the required output method
  • Pay attention to codebase_rag/cli.py - needs to move strings to proper constant files and use correct output method

Important Files Changed

Filename Overview
codebase_rag/cli.py Added version flag support with hardcoded strings and incorrect output method
codebase_rag/tests/test_cli_smoke.py Added comprehensive test for version flag with hardcoded string

Last reviewed commit: 50b9e49

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

None,
"--version",
"-v",
help="Show the version and exit.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hardcoded string should be moved to cli_help.py as HELP_VERSION

Suggested change
help="Show the version and exit.",
help=ch.HELP_VERSION,

Context Used: Rule from dashboard - ## Technical Requirements

Agentic Framework

  • PydanticAI Only: This project uses PydanticAI... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: codebase_rag/cli.py
Line: 72

Comment:
hardcoded string should be moved to `cli_help.py` as `HELP_VERSION`

```suggestion
        help=ch.HELP_VERSION,
```

**Context Used:** Rule from `dashboard` - ## Technical Requirements

### Agentic Framework
- **PydanticAI Only**: This project uses PydanticAI... ([source](https://app.greptile.com/review/custom-context?memory=d4240b05-b763-467a-a6bf-94f73e8b6859))

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.


def _version_callback(value: bool) -> None:
if value:
typer.echo(f"code-graph-rag version {get_version('code-graph-rag')}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hardcoded format string should be moved to constants.py as CLI_MSG_VERSION

Also, use app_context.console.print() instead of typer.echo() per coding standards (Loguru Over Print section)

Context Used: Rule from dashboard - ## Technical Requirements

Agentic Framework

  • PydanticAI Only: This project uses PydanticAI... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: codebase_rag/cli.py
Line: 40

Comment:
hardcoded format string should be moved to `constants.py` as `CLI_MSG_VERSION`

Also, use `app_context.console.print()` instead of `typer.echo()` per coding standards (Loguru Over Print section)

**Context Used:** Rule from `dashboard` - ## Technical Requirements

### Agentic Framework
- **PydanticAI Only**: This project uses PydanticAI... ([source](https://app.greptile.com/review/custom-context?memory=d4240b05-b763-467a-a6bf-94f73e8b6859))

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

assert result.returncode == 0, (
f"{flag} exited with code {result.returncode}: {result.stderr}"
)
assert result.stdout.startswith("code-graph-rag version "), (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hardcoded string should reference the constant from constants.py (e.g., cs.CLI_MSG_VERSION_PREFIX)

Context Used: Rule from dashboard - ## Technical Requirements

Agentic Framework

  • PydanticAI Only: This project uses PydanticAI... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: codebase_rag/tests/test_cli_smoke.py
Line: 53

Comment:
hardcoded string should reference the constant from `constants.py` (e.g., `cs.CLI_MSG_VERSION_PREFIX`)

**Context Used:** Rule from `dashboard` - ## Technical Requirements

### Agentic Framework
- **PydanticAI Only**: This project uses PydanticAI... ([source](https://app.greptile.com/review/custom-context?memory=d4240b05-b763-467a-a6bf-94f73e8b6859))

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

@teamauresta teamauresta force-pushed the feat/add-version-command branch from 50b9e49 to 8aacac7 Compare February 23, 2026 00:06
@teamauresta
Copy link
Author

Closes #239

Implements cgr --version and cgr -v commands that display the
current package version read from importlib.metadata.

Acceptance criteria from issue vitali87#239:
- cgr --version and cgr -v both work
- Version read from package metadata (not hardcoded)
- Output format: code-graph-rag version X.Y.Z

Changes:
- Add _version_callback using app_context.console.print (highlight=False)
- Add HELP_VERSION to cli_help.py
- Add CLI_MSG_VERSION to constants.py
- Use ch.HELP_VERSION and cs.CLI_MSG_VERSION (no hardcoded strings)
- Add test_version_flag() to test_cli_smoke.py referencing cs.CLI_MSG_VERSION
@teamauresta teamauresta force-pushed the feat/add-version-command branch from 8aacac7 to 66810a3 Compare February 23, 2026 02:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant