Skip to content

Commit 20093b2

Browse files
kevinjqliuCopilot
andcommitted
use args_conflicts_with_subcommands
Co-authored-by: Copilot <copilot@github.com>
1 parent a15df5e commit 20093b2

2 files changed

Lines changed: 43 additions & 27 deletions

File tree

tpchgen-cli/bin/main.rs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,16 @@ tpchgen-cli parquet -s 100 --tables=lineitem --parts=10 --output-dir=/tmp/tpch
5555
# Generate scale factor one in current directory, seeing debug output
5656
5757
RUST_LOG=debug tpchgen-cli -s 1 --output-dir=/tmp/tpch
58-
"#
58+
"#,
59+
args_conflicts_with_subcommands = true
5960
)]
6061
struct Cli {
6162
#[command(subcommand)]
6263
command: Option<Commands>,
6364

65+
// Top-level args are only used when no subcommand is given (legacy path).
66+
// args_conflicts_with_subcommands prevents these from being silently ignored
67+
// when a subcommand is present (e.g. `tpchgen-cli -s 10 parquet` is an error).
6468
#[command(flatten)]
6569
args: TopLevelArgs,
6670
}
@@ -296,27 +300,6 @@ impl Cli {
296300
/// Main function to run the generation
297301
#[allow(deprecated)]
298302
async fn main(self) -> io::Result<()> {
299-
// Error if deprecated top-level flags are used with a subcommand
300-
if self.command.is_some() {
301-
if self.args.format.is_some() {
302-
return Err(io::Error::new(
303-
io::ErrorKind::InvalidInput,
304-
"Cannot use --format with a subcommand. Use the subcommand directly, e.g. `tpchgen-cli parquet`",
305-
));
306-
}
307-
if self.args.parquet_compression.is_some() {
308-
return Err(io::Error::new(
309-
io::ErrorKind::InvalidInput,
310-
"Cannot use --parquet-compression with a subcommand. Use `tpchgen-cli parquet --compression=...` instead",
311-
));
312-
}
313-
if self.args.parquet_row_group_bytes.is_some() {
314-
return Err(io::Error::new(
315-
io::ErrorKind::InvalidInput,
316-
"Cannot use --parquet-row-group-bytes with a subcommand. Use `tpchgen-cli parquet --row-group-bytes=...` instead",
317-
));
318-
}
319-
}
320303
match self.command {
321304
Some(Commands::Tbl(args)) => args.run().await,
322305
Some(Commands::Csv(args)) => args.run().await,

tpchgen-cli/tests/cli_integration.rs

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ fn test_format_with_subcommand_conflict() {
740740
.assert()
741741
.failure()
742742
.stderr(predicates::str::contains(
743-
"Cannot use --format with a subcommand",
743+
"cannot be used with",
744744
));
745745
}
746746

@@ -763,7 +763,7 @@ fn test_parquet_compression_with_subcommand_conflict() {
763763
.assert()
764764
.failure()
765765
.stderr(predicates::str::contains(
766-
"Cannot use --parquet-compression with a subcommand",
766+
"cannot be used with",
767767
));
768768

769769
// With tbl subcommand
@@ -780,7 +780,7 @@ fn test_parquet_compression_with_subcommand_conflict() {
780780
.assert()
781781
.failure()
782782
.stderr(predicates::str::contains(
783-
"Cannot use --parquet-compression with a subcommand",
783+
"cannot be used with",
784784
));
785785
}
786786

@@ -803,7 +803,7 @@ fn test_parquet_row_group_bytes_with_subcommand_conflict() {
803803
.assert()
804804
.failure()
805805
.stderr(predicates::str::contains(
806-
"Cannot use --parquet-row-group-bytes with a subcommand",
806+
"cannot be used with",
807807
));
808808

809809
// With csv subcommand
@@ -820,10 +820,43 @@ fn test_parquet_row_group_bytes_with_subcommand_conflict() {
820820
.assert()
821821
.failure()
822822
.stderr(predicates::str::contains(
823-
"Cannot use --parquet-row-group-bytes with a subcommand",
823+
"cannot be used with",
824824
));
825825
}
826826

827+
/// Test that common args before a subcommand are rejected
828+
#[test]
829+
fn test_common_args_with_subcommand_conflict() {
830+
let temp_dir = tempdir().expect("Failed to create temporary directory");
831+
832+
// -s before subcommand should error
833+
cargo_bin_cmd!("tpchgen-cli")
834+
.arg("-s")
835+
.arg("0.01")
836+
.arg("parquet")
837+
.arg("--tables")
838+
.arg("part")
839+
.arg("--output-dir")
840+
.arg(temp_dir.path())
841+
.assert()
842+
.failure()
843+
.stderr(predicates::str::contains(
844+
"cannot be used with",
845+
));
846+
847+
// -s after subcommand should work
848+
cargo_bin_cmd!("tpchgen-cli")
849+
.arg("parquet")
850+
.arg("-s")
851+
.arg("0.01")
852+
.arg("--tables")
853+
.arg("part")
854+
.arg("--output-dir")
855+
.arg(temp_dir.path())
856+
.assert()
857+
.success();
858+
}
859+
827860
/// Test that running with no --format and no subcommand defaults to TBL
828861
#[test]
829862
fn test_default_format_is_tbl() {

0 commit comments

Comments
 (0)