Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ To generate a project from the template:
copier copy path/to/project/template path/to/destination
```

Generate a JSON Schema for your `copier.yml` with `copier schema`.

- Or in Python code, programmatically:

```python
Expand Down
43 changes: 42 additions & 1 deletion copier/_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Command line entrypoint. This module declares the Copier CLI applications.

Basically, there are 4 different commands you can run:
Basically, there are 5 different commands you can run:

- `copier`, the main app, which is a shortcut for the
`copy` and `update` subapps.
Expand Down Expand Up @@ -48,6 +48,15 @@
copier check-update
```

- `copier schema` to generate a JSON Schema for
`copier.yml` files.

!!! example

```sh
copier schema -o copier.schema.json
```

Below are the docs of each one of those.

CLI help generated from `copier --help-all`:
Expand Down Expand Up @@ -565,3 +574,35 @@ def inner() -> int:
return 0

return _handle_exceptions(inner)


@CopierApp.subcommand("schema")
class CopierSchemaSubApp(cli.Application):
"""The `copier schema` subcommand.

Use this subcommand to generate a JSON Schema for copier.yml files.
The schema can be used by IDEs for autocompletion, hints, and validation.
"""

DESCRIPTION = "Generate a JSON Schema for copier.yml files"

output = cli.SwitchAttr(
["-o", "--output"],
help="Write the schema to a file path instead of stdout.",
)

def main(self) -> int:
"""Generate and output the JSON Schema."""

def inner() -> None:
from ._schema import generate_copier_yml_schema

schema = generate_copier_yml_schema()
text = json.dumps(schema, indent=2) + "\n"

if self.output:
Path(self.output).write_text(text)
else:
print(text)

return _handle_exceptions(inner)
Loading