fix: Use clap's possible_values method

This gets us built-in help text and error messages, and does less work
before failing because of an unsupported value.

Before this change, the help text was:

```
OPTIONS:
        --compression-level <compression_level>
            Compression level: max or compatibility (default). [default: compatibility]
```

After this change, the help text is:

```
OPTIONS:
        --compression-level <compression_level>
            How much to compress the output data. 'max' compresses the most; 'compatibility' compresses in a manner more
            likely to be readable by other tools. [default: compatibility]  [possible values: max, compatibility]
```

Before this change, if you supplied an unsupported value, the error was:

```
[2020-06-29T14:47:42Z INFO  delorean::commands::convert] convert starting
[2020-06-29T14:47:42Z INFO  delorean::commands::convert] Preparing to convert 591 bytes from tests/fixtures/lineproto/temperature.lp
Conversion failed: Error creating a parquet table writer Unknown compression level 'foo'. Valid options 'max' or 'compatibility'
```

After this change, the error is:

```
error: 'foo' isn't a valid value for '--compression-level <compression_level>'
	[possible values: compatibility, max]
```
pull/24376/head
Carol (Nichols || Goulding) 2020-06-29 10:16:23 -04:00
parent 724a4edcbf
commit c6f2508abe
2 changed files with 6 additions and 10 deletions

View File

@ -69,7 +69,9 @@ Examples:
Arg::with_name("compression_level")
.short("c")
.long("compression-level")
.help("Compression level: max or compatibility (default).")
.help("How much to compress the output data. 'max' compresses the most; 'compatibility' compresses in a manner more likely to be readable by other tools.")
.takes_value(true)
.possible_values(&["max", "compatibility"])
.default_value("compatibility"),
),
)

View File

@ -57,15 +57,9 @@ fn convert_bad_compression_level() {
.arg("/tmp")
.assert();
assert
.failure()
.code(1)
.stderr(predicate::str::contains(
"Conversion failed: Error creating a parquet table writer",
))
.stderr(predicate::str::contains(
r#"Unknown compression level 'maxxx'. Valid options 'max' or 'compatibility'"#,
));
assert.failure().code(1).stderr(predicate::str::contains(
"error: 'maxxx' isn't a valid value for '--compression-level <compression_level>",
));
}
#[test]