Skip to content

feat: add --version command to CLI#298

Open
tibisabau wants to merge 2 commits intovitali87:mainfrom
tibisabau:feat/add-version-command-to-cli
Open

feat: add --version command to CLI#298
tibisabau wants to merge 2 commits intovitali87:mainfrom
tibisabau:feat/add-version-command-to-cli

Conversation

@tibisabau
Copy link

Description

Implemented a --version command that displays the current package version. The version is dynamically read from package metadata using importlib.metadata.version('graph-code') to avoid hardcoding. Both cgr --version and cgr -v work correctly, outputting the format: code-graph-rag version X.Y.Z.

The implementation uses Typer's callback pattern with is_eager=True to ensure the version check occurs before other option processing, and raises typer.Exit() to cleanly terminate after displaying the version.

Closes #239.

Checklist if Applicable

  • The tests passed – uv run cgr --version and uv run cgr -v
  • Linting passed – make pre-commit (formatting, linting, type checking, security checks, unit tests)
  • Documentation has been added
  • CHANGELOG.md has been updated

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @tibisabau, 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 adding a convenient way for users to query the application's version. This improves user experience and simplifies maintenance by dynamically retrieving version information, ensuring it's always up-to-date with the installed package.

Highlights

  • CLI Version Command: Introduced a --version command (and its shorthand -v) to the CLI, allowing users to display the current package version of code-graph-rag.
  • Dynamic Version Retrieval: The version is now dynamically read from the package metadata using importlib.metadata.version('graph-code'), eliminating the need for hardcoding and ensuring accuracy.
  • Clean Exit Handling: The implementation leverages Typer's is_eager=True callback pattern and typer.Exit() to ensure the version check occurs early and the application terminates cleanly after displaying the version.
Changelog
  • codebase_rag/cli.py
    • Added importlib.metadata.version to retrieve package version dynamically.
    • Implemented _version_callback function to print the version and exit.
    • Integrated --version and -v options into the global CLI callback using typer.Option with is_eager=True and a callback for version display.
  • uv.lock
    • Updated the graph-code package version from 0.0.48 to 0.0.50.
Activity
  • The author confirmed that tests for uv run cgr --version and uv run cgr -v passed.
  • Linting checks, including formatting, linting, type checking, security checks, and unit tests, passed via make pre-commit.
  • This pull request addresses and closes issue Add --version command to CLI #239.
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

This pull request introduces a --version command to the CLI, which is a great addition for usability. The implementation is clean and follows best practices for Typer applications by using an eager callback that exits after printing the version. I appreciate the use of importlib.metadata.version to dynamically fetch the package version, which avoids hardcoding and ensures the version is always in sync with the package metadata. The changes are correct and well-executed. No issues found.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 5, 2026

Greptile Overview

Greptile Summary

This PR adds a global --version/-v option to the Typer CLI (implemented via an eager callback) that prints code-graph-rag version X.Y.Z by reading the installed package’s distribution metadata using importlib.metadata.version('graph-code'), then exits early.

The change is localized to codebase_rag/cli.py, which defines the main Typer app and global options; the lockfile updates the editable package version. README changes appear to be a no-op re-save.

Main issue to address before merge: the --version path can currently crash with PackageNotFoundError when distribution metadata for graph-code isn’t available (e.g., running from a source checkout without an installed package or if the dist name differs), so it needs explicit handling to keep cgr --version reliable.

Confidence Score: 4/5

  • Mostly safe to merge after fixing the --version crash path when package metadata is unavailable.
  • The feature is small and isolated to the CLI callback. The only verified functional risk is an unhandled importlib.metadata.PackageNotFoundError that can break cgr --version in common dev/non-installed scenarios.
  • codebase_rag/cli.py

Important Files Changed

Filename Overview
README.md No functional changes; file appears to be re-saved with identical content (diff is whitespace/no-op).
codebase_rag/cli.py Adds --version/-v eager option via Typer callback; currently crashes if package metadata for graph-code is unavailable.
uv.lock Lockfile update bumps editable graph-code version to 0.0.50; no code changes.

Sequence Diagram

sequenceDiagram
  participant User
  participant Typer as CLI (typer)
  participant CLI as codebase_rag/cli.py
  participant Meta as importlib.metadata
  participant Console as app_context.console

  User->>Typer: cgr --version / -v
  Typer->>CLI: invoke eager option callback
  CLI->>Meta: version('graph-code')
  alt distribution metadata present
    Meta-->>CLI: "X.Y.Z"
    CLI->>Console: print "code-graph-rag version X.Y.Z"
    CLI-->>Typer: raise typer.Exit()
  else metadata missing
    Meta-->>CLI: raise PackageNotFoundError
    CLI-->>Typer: unhandled exception (crash)
  end
Loading

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.

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

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.

Add --version command to CLI

1 participant