From 8c6c1624178a38d976ecc3ffe3800c5d8e65b8ae Mon Sep 17 00:00:00 2001 From: Petr Date: Sat, 21 Mar 2026 12:17:02 +0100 Subject: [PATCH] Fix: --sql not required when --stdin is used argparse was rejecting --stdin mode because --sql was required=True. Changed to required=False with runtime validation in main(). --- src/remote_query.py | 7 ++++++- tests/test_remote_query.py | 9 +++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/remote_query.py b/src/remote_query.py index 3a6fa1c..a1ad202 100644 --- a/src/remote_query.py +++ b/src/remote_query.py @@ -481,7 +481,8 @@ Examples: ) parser.add_argument( "--sql", - required=True, + required=False, # not required when --stdin is used + default=None, help="DuckDB SQL query (executed after all views are registered)", ) parser.add_argument( @@ -604,6 +605,10 @@ def main(argv: Optional[list[str]] = None) -> None: ) return + # Validate --sql is provided when not using --stdin + if not args.sql: + parser.error("--sql is required (or use --stdin for JSON input)") + execute_remote_query( sql=args.sql, bq_registrations=args.bq_registrations, diff --git a/tests/test_remote_query.py b/tests/test_remote_query.py index f719fef..72b7e8e 100644 --- a/tests/test_remote_query.py +++ b/tests/test_remote_query.py @@ -161,11 +161,12 @@ def _patched_duckdb_connect(*args, **kwargs): class TestCLIArgParsing: """Test _parse_register_bq() and build_parser().""" - def test_requires_sql(self): - """Parser should fail when --sql is missing.""" + def test_sql_defaults_to_none(self): + """Parser allows --sql to be omitted (for --stdin mode).""" parser = build_parser() - with pytest.raises(SystemExit): - parser.parse_args([]) + args = parser.parse_args(["--stdin"]) + assert args.sql is None + assert args.stdin is True def test_register_bq_parsing(self): """'alias=SELECT ...' parses into (alias, sql) tuple."""