Skip to content

Commit eca36c0

Browse files
committed
Handle -v, -h
Fixes #1097
1 parent 6d7eed8 commit eca36c0

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ jobs:
110110
# coverage for conflict error messages
111111
- run: '! pkgx yarn --version'
112112
# coverage for display-name resolution
113-
- run: pkgx +agg
113+
- run: pkgx -v +agg
114114

115115
- name: generate coverage
116116
run: |

crates/cli/src/args.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub struct Flags {
1010
pub quiet: bool,
1111
pub silent: bool,
1212
pub json: bool,
13+
pub version_n_continue: bool,
1314
}
1415

1516
pub struct Args {
@@ -29,6 +30,7 @@ pub fn parse() -> Args {
2930
let mut json: bool = false;
3031
let mut find_program = false;
3132
let mut collecting_args = false;
33+
let mut version_n_continue = false;
3234

3335
for arg in std::env::args().skip(1) {
3436
if collecting_args {
@@ -86,8 +88,10 @@ pub fn parse() -> Args {
8688
quiet = true
8789
}
8890
}
91+
'h' => mode = Mode::Help,
8992
's' => silent = true,
9093
'j' => json = true,
94+
'v' => version_n_continue = true,
9195
_ => panic!("unknown argument: -{}", c),
9296
}
9397
}
@@ -107,6 +111,7 @@ pub fn parse() -> Args {
107111
silent,
108112
json,
109113
quiet,
114+
version_n_continue,
110115
},
111116
}
112117
}

crates/cli/src/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ async fn main() -> Result<(), Box<dyn Error>> {
2525
find_program,
2626
} = args::parse();
2727

28+
if flags.version_n_continue {
29+
eprintln!("pkgx {}", env!("CARGO_PKG_VERSION"));
30+
}
31+
2832
match mode {
2933
args::Mode::Help => {
3034
println!("{}", help::usage());
@@ -234,10 +238,12 @@ async fn main() -> Result<(), Box<dyn Error>> {
234238
println!("{}", json);
235239
}
236240
Ok(())
237-
} else {
241+
} else if !flags.version_n_continue {
238242
clear_progress_bar();
239243
eprintln!("{}", help::usage());
240244
std::process::exit(2);
245+
} else {
246+
Ok(())
241247
}
242248
}
243249

0 commit comments

Comments
 (0)