Skip to content

Commit a15df5e

Browse files
kevinjqliuCopilot
andcommitted
error when mixing top level option with subcommand
Co-authored-by: Copilot <copilot@github.com>
1 parent d3cfe89 commit a15df5e

2 files changed

Lines changed: 100 additions & 6 deletions

File tree

tpchgen-cli/bin/main.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,26 @@ impl Cli {
296296
/// Main function to run the generation
297297
#[allow(deprecated)]
298298
async fn main(self) -> io::Result<()> {
299-
// Error if both --format and a subcommand are specified
300-
if self.args.format.is_some() && self.command.is_some() {
301-
return Err(io::Error::new(
302-
io::ErrorKind::InvalidInput,
303-
"Cannot use --format with a subcommand. Use the subcommand directly, e.g. `tpchgen-cli parquet`",
304-
));
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+
}
305319
}
306320
match self.command {
307321
Some(Commands::Tbl(args)) => args.run().await,

tpchgen-cli/tests/cli_integration.rs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,86 @@ fn test_format_with_subcommand_conflict() {
744744
));
745745
}
746746

747+
/// Test that using --parquet-compression together with a subcommand errors
748+
#[test]
749+
fn test_parquet_compression_with_subcommand_conflict() {
750+
let temp_dir = tempdir().expect("Failed to create temporary directory");
751+
752+
// With parquet subcommand
753+
cargo_bin_cmd!("tpchgen-cli")
754+
.arg("--parquet-compression")
755+
.arg("SNAPPY")
756+
.arg("parquet")
757+
.arg("--scale-factor")
758+
.arg("0.001")
759+
.arg("--tables")
760+
.arg("part")
761+
.arg("--output-dir")
762+
.arg(temp_dir.path())
763+
.assert()
764+
.failure()
765+
.stderr(predicates::str::contains(
766+
"Cannot use --parquet-compression with a subcommand",
767+
));
768+
769+
// With tbl subcommand
770+
cargo_bin_cmd!("tpchgen-cli")
771+
.arg("--parquet-compression")
772+
.arg("SNAPPY")
773+
.arg("tbl")
774+
.arg("--scale-factor")
775+
.arg("0.001")
776+
.arg("--tables")
777+
.arg("part")
778+
.arg("--output-dir")
779+
.arg(temp_dir.path())
780+
.assert()
781+
.failure()
782+
.stderr(predicates::str::contains(
783+
"Cannot use --parquet-compression with a subcommand",
784+
));
785+
}
786+
787+
/// Test that using --parquet-row-group-bytes together with a subcommand errors
788+
#[test]
789+
fn test_parquet_row_group_bytes_with_subcommand_conflict() {
790+
let temp_dir = tempdir().expect("Failed to create temporary directory");
791+
792+
// With parquet subcommand
793+
cargo_bin_cmd!("tpchgen-cli")
794+
.arg("--parquet-row-group-bytes")
795+
.arg("1000000")
796+
.arg("parquet")
797+
.arg("--scale-factor")
798+
.arg("0.001")
799+
.arg("--tables")
800+
.arg("part")
801+
.arg("--output-dir")
802+
.arg(temp_dir.path())
803+
.assert()
804+
.failure()
805+
.stderr(predicates::str::contains(
806+
"Cannot use --parquet-row-group-bytes with a subcommand",
807+
));
808+
809+
// With csv subcommand
810+
cargo_bin_cmd!("tpchgen-cli")
811+
.arg("--parquet-row-group-bytes")
812+
.arg("1000000")
813+
.arg("csv")
814+
.arg("--scale-factor")
815+
.arg("0.001")
816+
.arg("--tables")
817+
.arg("part")
818+
.arg("--output-dir")
819+
.arg(temp_dir.path())
820+
.assert()
821+
.failure()
822+
.stderr(predicates::str::contains(
823+
"Cannot use --parquet-row-group-bytes with a subcommand",
824+
));
825+
}
826+
747827
/// Test that running with no --format and no subcommand defaults to TBL
748828
#[test]
749829
fn test_default_format_is_tbl() {

0 commit comments

Comments
 (0)