From f3db6bb0cea5abca98e83f80eed34febdc5a9ee1 Mon Sep 17 00:00:00 2001 From: Christodoulos Tsoulloftas Date: Sun, 22 Dec 2024 08:58:36 +0200 Subject: [PATCH] Deprecate xsdata shorthand --- README.md | 2 +- docs/codegen/config.md | 2 +- docs/codegen/dtd_modeling.md | 2 +- docs/codegen/intro.md | 8 ++++---- docs/codegen/samples_modeling.md | 4 ++-- docs/codegen/wsdl_modeling.md | 2 +- docs/plugins/how_to.md | 2 +- tests/test_cli.py | 2 +- xsdata/cli.py | 15 ++++++++++++++- 9 files changed, 26 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index ec14b654f..ae00e7f81 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ $ pip install xsdata[cli,lxml,soap] ```console $ # Generate models -$ xsdata tests/fixtures/primer/order.xsd --package tests.fixtures.primer +$ xsdata generate tests/fixtures/primer/order.xsd --package tests.fixtures.primer ``` ```python diff --git a/docs/codegen/config.md b/docs/codegen/config.md index dfc731e22..3c65cf5f6 100644 --- a/docs/codegen/config.md +++ b/docs/codegen/config.md @@ -26,7 +26,7 @@ print(output.getvalue()) **Usage** ```console -$ xsdata --config project/.xsdata.xml +$ xsdata generate --config project/.xsdata.xml ``` !!! Info "CLI options override the project configuration settings." diff --git a/docs/codegen/dtd_modeling.md b/docs/codegen/dtd_modeling.md index e6219cc8b..d4d9da1ca 100644 --- a/docs/codegen/dtd_modeling.md +++ b/docs/codegen/dtd_modeling.md @@ -15,7 +15,7 @@ $ pip install xsdata[lxml] ## Example ```console -$ xsdata --package tests.fixtures.dtd.models tests/fixtures/dtd/complete_example.dtd +$ xsdata generate --package tests.fixtures.dtd.models tests/fixtures/dtd/complete_example.dtd ``` === "DTD Definition" diff --git a/docs/codegen/intro.md b/docs/codegen/intro.md index 87d620b44..43839639f 100644 --- a/docs/codegen/intro.md +++ b/docs/codegen/intro.md @@ -27,13 +27,13 @@ You can instruct the cli to search all subdirectories recursively with the `-r, --recursive` flag. ```console -$ xsdata project/schemas -$ xsdata project/schemas --recursive +$ xsdata generate project/schemas +$ xsdata generate project/schemas --recursive ``` ## Use a filename or URI as source ```console -$ xsdata project/schemas/feed.xsd -$ xsdata http://www.gstatic.com/localfeed/local_feed.xsd +$ xsdata generate project/schemas/feed.xsd +$ xsdata generate http://www.gstatic.com/localfeed/local_feed.xsd ``` diff --git a/docs/codegen/samples_modeling.md b/docs/codegen/samples_modeling.md index e4bc88844..67f16d85b 100644 --- a/docs/codegen/samples_modeling.md +++ b/docs/codegen/samples_modeling.md @@ -8,7 +8,7 @@ merge and flatten duplicate classes, fields and field types. ## XML Documents ```console -$ xsdata --package tests.fixtures.artists tests/fixtures/artists +$ xsdata generate --package tests.fixtures.artists tests/fixtures/artists ``` === "Sample #1" @@ -38,7 +38,7 @@ $ xsdata --package tests.fixtures.artists tests/fixtures/artists ## JSON Documents ```console -$ xsdata --package tests.fixtures.series tests/fixtures/series/samples +$ xsdata generate --package tests.fixtures.series tests/fixtures/series/samples ``` === "Sample #1" diff --git a/docs/codegen/wsdl_modeling.md b/docs/codegen/wsdl_modeling.md index 63fc1ef6f..de8445b89 100644 --- a/docs/codegen/wsdl_modeling.md +++ b/docs/codegen/wsdl_modeling.md @@ -13,7 +13,7 @@ $ pip install xsdata[cli,soap] ``` ```console -$ xsdata --package calculator http://www.dneonline.com/calculator.asmx?WSDL +$ xsdata generate --package calculator http://www.dneonline.com/calculator.asmx?WSDL ``` ## Message Model diff --git a/docs/plugins/how_to.md b/docs/plugins/how_to.md index 0a6318954..d19472f20 100644 --- a/docs/plugins/how_to.md +++ b/docs/plugins/how_to.md @@ -21,7 +21,7 @@ CodeWriter.register_generator("awesome", AwesomeGenerator) Which can be used during code generation. ```console -$ xsdata --output awesome +$ xsdata generate --output awesome ``` ## `xsdata.plugins.class_types` diff --git a/tests/test_cli.py b/tests/test_cli.py index a8326e98d..b9e5a45e8 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -53,7 +53,7 @@ def test_generate_with_error(self, mock_process): mock_process.side_effect = CodegenError("Testing", foo="bar") source = fixtures_dir.joinpath("defxmlschema/chapter03.xsd") - result = self.runner.invoke(cli, [str(source), "--package", "foo"]) + result = self.runner.invoke(cli, ["generate", str(source), "--package", "foo"]) expected = "=========\n" "Error: Testing\n" "foo: bar\n" self.assertIn(expected, result.output) diff --git a/xsdata/cli.py b/xsdata/cli.py index 3be1c8f43..9b32e0a02 100644 --- a/xsdata/cli.py +++ b/xsdata/cli.py @@ -36,7 +36,20 @@ logging.captureWarnings(True) -@click.group(cls=DefaultGroup, default="generate", default_if_no_args=False) +class DeprecatedDefaultGroup(DefaultGroup): + """Deprecated default group.""" + + def get_command(self, ctx: click.Context, cmd_name: str) -> click.Command: + """Override to deprecate xsdata shorthand.""" + if cmd_name not in self.commands: + logger.warning( + "`xsdata ` is deprecated. " + "Use `xsdata generate ` instead." + ) + return super().get_command(ctx, cmd_name) + + +@click.group(cls=DeprecatedDefaultGroup, default="generate", default_if_no_args=False) @click.pass_context @click.version_option(__version__) def cli(ctx: click.Context, **kwargs: Any):