Rollup merge of #99100 - Smittyvb:test-cli-binary-name, r=thomcc

Fix binary name in help message for test binaries

Currently the help output for a test binary uses the first argument instead of the binary name in the help output:

```
$ cargo test -- --help
...
Usage: --help [OPTIONS] [FILTERS...]
...
```

This fixes it to use the name of the binary (or `...` if there is no binary name passed on argv):

```
$ cargo test -- --help
...
Usage: /tmp/x/target/debug/deps/x-80c11a15ad4e1bf3 [OPTIONS] [FILTERS...]
...
```
This commit is contained in:
Matthias Krüger 2022-07-10 11:52:16 +02:00 committed by GitHub
commit 76f968dadc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -196,6 +196,7 @@ fn usage(binary: &str, options: &getopts::Options) {
pub fn parse_opts(args: &[String]) -> Option<OptRes> {
// Parse matches.
let opts = optgroups();
let binary = args.get(0).map(|c| &**c).unwrap_or("...");
let args = args.get(1..).unwrap_or(args);
let matches = match opts.parse(args) {
Ok(m) => m,
@ -205,7 +206,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
// Check if help was requested.
if matches.opt_present("h") {
// Show help and do nothing more.
usage(&args[0], &opts);
usage(binary, &opts);
return None;
}