Merge pull request #39 from 0xrsydn/fix/version-flag

fix: accept idx --version / -V
This commit is contained in:
brutaljokerz 2026-10-15 11:22:13 +07:00 • committed by GitHub
commit 8747bfb977
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 1 deletions

View file

@ -19,6 +19,8 @@ pub enum Shell {
#[command( #[command(
name = "idx", name = "idx",
bin_name = "idx", bin_name = "idx",
version,
disable_version_flag = true,
about = "CLI tool for Indonesian stock market (IDX) analysis", about = "CLI tool for Indonesian stock market (IDX) analysis",
long_about = "idx-cli is a Rust command-line tool for Indonesian stock market (IDX) analysis.\nIt supports quote lookup, historical data, local caching, and output formats for both humans and AI agents." long_about = "idx-cli is a Rust command-line tool for Indonesian stock market (IDX) analysis.\nIt supports quote lookup, historical data, local caching, and output formats for both humans and AI agents."
)] )]
@ -41,6 +43,9 @@ pub struct Cli {
pub offline: bool, pub offline: bool,
#[arg(long, global = true, help = "Bypass local cache")] #[arg(long, global = true, help = "Bypass local cache")]
pub no_cache: bool, pub no_cache: bool,
// `idx version` is the documented form; `--version` is a hidden alias.
#[arg(short = 'V', long, action = clap::ArgAction::Version, hide = true)]
version: Option<bool>,
#[command(subcommand)] #[command(subcommand)]
pub command: Commands, pub command: Commands,
} }

View file

@ -418,6 +418,17 @@ fn version_prints_cargo_version() {
.stdout(predicate::str::contains(env!("CARGO_PKG_VERSION"))); .stdout(predicate::str::contains(env!("CARGO_PKG_VERSION")));
} }
#[test]
fn version_flags_print_cargo_version() {
for flag in ["--version", "-V"] {
test_bin("version-flag")
.arg(flag)
.assert()
.success()
.stdout(format!("idx {}\n", env!("CARGO_PKG_VERSION")));
}
}
#[test] #[test]
fn quote_table_with_mock_contains_expected_columns() { fn quote_table_with_mock_contains_expected_columns() {
test_bin("quote-table") test_bin("quote-table")

View file

@ -439,7 +439,7 @@ _idx() {
case "${cmd}" in case "${cmd}" in
idx) idx)
opts="-o -q -v -h --output --no-color --quiet --verbose --offline --no-cache --help stocks config cache ownership completions version help" opts="-o -q -v -V -h --output --no-color --quiet --verbose --offline --no-cache --version --help stocks config cache ownership completions version help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0 return 0