Skip to content

Commit

Permalink
Deprecate xsdata <source> shorthand
Browse files Browse the repository at this point in the history
  • Loading branch information
tefra committed Dec 22, 2024
1 parent 1f4c423 commit f3db6bb
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/codegen/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
2 changes: 1 addition & 1 deletion docs/codegen/dtd_modeling.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions docs/codegen/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
4 changes: 2 additions & 2 deletions docs/codegen/samples_modeling.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion docs/codegen/wsdl_modeling.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/plugins/how_to.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 14 additions & 1 deletion xsdata/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <source> shorthand."""
if cmd_name not in self.commands:
logger.warning(
"`xsdata <SOURCE>` is deprecated. "
"Use `xsdata generate <SOURCE>` 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):
Expand Down

0 comments on commit f3db6bb

Please sign in to comment.