Skip to content

Commit

Permalink
feature: print version with --version
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsen1 committed Jan 30, 2025
1 parent f72d658 commit 8982e82
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ categories = ["command-line-utilities", "development-tools"]
anyhow = "1.0"
byte-unit = "4.0"
clap = { version = "4.4", features = ["derive"] }
clap-config-file = "0.4.0"
clap-config-file = "0.5.0"
crossbeam = "0.8"
ignore = "0.4"
indicatif = "0.17"
Expand Down
11 changes: 11 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ pub struct YekConfig {
#[config_arg(positional)]
pub input_dirs: Vec<String>,

/// Print version of yek
#[config_arg(long = "version", short = 'V')]
pub version: bool,

/// Max size per chunk. e.g. "10MB" or "128K" or when using token counting mode, "100" or "128K"
#[config_arg(default_value = "10MB")]
pub max_size: String,
Expand Down Expand Up @@ -89,6 +93,7 @@ impl Default for YekConfig {
fn default() -> Self {
Self {
input_dirs: Vec::new(),
version: false,
max_size: "10MB".to_string(),
tokens: String::new(),
json: false,
Expand Down Expand Up @@ -156,6 +161,12 @@ impl YekConfig {
// 1) parse from CLI and optional config file:
let mut cfg = YekConfig::parse();

// Handle version flag
if cfg.version {
println!("{}", env!("CARGO_PKG_VERSION"));
std::process::exit(0);
}

// 2) compute derived fields:
cfg.token_mode = !cfg.tokens.is_empty();
let force_tty = std::env::var("FORCE_TTY").is_ok();
Expand Down

0 comments on commit 8982e82

Please sign in to comment.