Skip to content

Commit 417aefb

Browse files
feat: add --require-license strict mode flag
Closes #27
1 parent 7250335 commit 417aefb

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

src/json2sql/cli.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""CLI interface for json2sql using Typer."""
22

3+
import os
34
import sys
45
from pathlib import Path
56

@@ -24,13 +25,55 @@ def require_license(product: str) -> None: # type: ignore[misc]
2425
from .converter import JSONToSQLConverter
2526
from .dialects import Dialect
2627

28+
_require_license_strict: bool = False
29+
2730
app = typer.Typer(
2831
name="json2sql",
2932
help="Convert JSON files/datasets to SQL INSERT statements.",
3033
no_args_is_help=True,
3134
)
3235

3336

37+
@app.callback()
38+
def _app_callback(
39+
require_license_flag: bool = typer.Option(
40+
False,
41+
"--require-license",
42+
help=(
43+
"Exit with an error if revenueholdings-license is not installed "
44+
"or if the license check fails. "
45+
"Also enabled via REVENUEHOLDINGS_REQUIRE_LICENSE=1."
46+
),
47+
),
48+
) -> None:
49+
"""Convert JSON files/datasets to SQL INSERT statements."""
50+
global _require_license_strict
51+
_require_license_strict = require_license_flag or bool(
52+
os.environ.get("REVENUEHOLDINGS_REQUIRE_LICENSE")
53+
)
54+
55+
56+
def _check_license(tool_name: str) -> None:
57+
"""Check revenueholdings license; raise on failure if strict mode is enabled."""
58+
if os.environ.get("REVENUEHOLDINGS_LICENSE_BYPASS"):
59+
return
60+
try:
61+
from revenueholdings_license import require_license
62+
63+
require_license(tool_name)
64+
except ImportError:
65+
if _require_license_strict:
66+
typer.echo(
67+
"Error: revenueholdings-license is not installed. "
68+
"Install it with: pip install revenueholdings-license",
69+
err=True,
70+
)
71+
raise typer.Exit(code=1) from None
72+
except Exception:
73+
if _require_license_strict:
74+
raise
75+
76+
3477
@app.command()
3578
def convert(
3679
input_file: Path | None = typer.Argument( # noqa: B008
@@ -69,6 +112,7 @@ def convert(
69112
),
70113
):
71114
"""Convert a JSON file to SQL INSERT statements."""
115+
_check_license("json2sql")
72116

73117
# Validate dialect
74118
try:
@@ -115,6 +159,7 @@ def mcp() -> None:
115159
AI coding agents (Claude Code, Cursor, etc.) use this to interact
116160
with json2sql tools directly.
117161
"""
162+
_check_license("json2sql")
118163
try:
119164
from click_to_mcp import run # type: ignore[import-untyped]
120165
except ImportError:

0 commit comments

Comments
 (0)