Skip to content

Add --version option to CLI#43

Merged
technicalpickles merged 3 commits intomainfrom
add-version-option
Sep 11, 2025
Merged

Add --version option to CLI#43
technicalpickles merged 3 commits intomainfrom
add-version-option

Conversation

@technicalpickles
Copy link
Copy Markdown
Owner

Summary

Adds a --version option to the envsense CLI that displays the current version of the tool.

Changes

  • Added version support: Modified the clap #[command] attribute in src/main.rs to include version = env!("CARGO_PKG_VERSION")
  • Comprehensive testing: Added two new tests in tests/cli.rs:
    • version_flag_displays_version() - tests --version
    • version_short_flag_displays_version() - tests -V

Key Features

  • Automatic version detection: Uses env!("CARGO_PKG_VERSION") to pull version from Cargo.toml
  • Standard CLI behavior: Supports both --version and -V flags (clap default)
  • Proper output format: Displays envsense X.Y.Z format
  • No breaking changes: All existing CLI functionality remains intact

Testing

# Test the new functionality
cargo run -- --version
cargo run -- -V

# Run the test suite
cargo test --test cli

Example Output

$ envsense --version
envsense 0.2.2

$ envsense --help
Environment awareness utilities

Usage: envsense [OPTIONS] [COMMAND]

Commands:
  info   Show what envsense knows
  check  Evaluate predicates against the environment
  help   Print this message or the help of the given subcommand(s)

Options:
      --no-color  Disable color
  -h, --help      Print help
  -V, --version   Print version

This implements a standard CLI version option following Rust/clap best practices.

- Added version field to clap command configuration using env!('CARGO_PKG_VERSION')
- Added comprehensive tests for both --version and -V flags
- Version option displays 'envsense X.Y.Z' format
- Maintains compatibility with existing CLI functionality
Copilot AI review requested due to automatic review settings September 5, 2025 19:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds a standard --version option to the envsense CLI that displays the current version of the tool by leveraging Cargo's built-in version information.

  • Added version support to the CLI using env!("CARGO_PKG_VERSION") macro
  • Implemented comprehensive testing for both long and short version flags
  • Maintains backward compatibility with existing CLI functionality

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/main.rs Added version attribute to clap command configuration
tests/cli.rs Added two test functions to verify version flag functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@technicalpickles technicalpickles merged commit 1e230fa into main Sep 11, 2025
4 checks passed
@technicalpickles technicalpickles deleted the add-version-option branch September 11, 2025 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants