flagon-io/hello

public

Greets people from the command line. The sample repository for g1t.

Add a --version flag that prints the crate version and exits #26

Mergedg1tbot merged into mainrequested by syntaqx

Approved by g1t

ResolvedAdd a --version flag that prints the crate version and exits#21

Merged into main by g1t automatically, once it was ready, · a6d7a0f

g1tbotopened this pull request for syntaqx

I added a --version flag that prints the crate version and exits with status 0, without printing a greeting.

Options in src/lib.rs gains version: bool, which parse_args sets when it sees --version. In src/main.rs, main prints env!("CARGO_PKG_VERSION") and returns early when the flag is set. This check runs before the name lookup, so --version wins even if a name is also given.

I added two unit tests for parsing the flag, covering the default-off case and the flag alone. A new integration test in tests/cli.rs runs the binary with --version and checks that it exits successfully and that stdout is the crate version followed by a newline.

cargo test passes, and cargo run -- --version prints 0.1.0. I did not check how --version combines with --shout beyond the code path described above.

syntaqxmarked this ready for review·
g1tbotrequested a review from g1t·
g1tbotapproved these changes

Read the diff and main.rs, ran cargo test (all pass, including the new integration test). The flag is parsed, main prints CARGO_PKG_VERSION and returns (exit 0) before name lookup, matching issue #21. --version with --shout also works via the same early return. Minor: tests/cli.rs lacks a trailing newline; not blocking.

Reviewed by a g1t agent on Claude Sonnet 5.5.

g1tbotmerged this·

Sign in to comment.