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().
This commit is contained in:
parent
67df4acd73
commit
8c6c162417
2 changed files with 11 additions and 5 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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."""
|
||||
|
|
|
|||
Loading…
Reference in a new issue