22import os
33
44import click
5- from fastapi_mvc import Generator
5+ import copier
6+ from fastapi_mvc.cli import GeneratorCommand
7+ from fastapi_mvc.utils import require_fastapi_mvc_project
8+ from fastapi_mvc.constants import ANSWERS_FILE
69
710
811cmd_short_help = "Run custom generator {{generator_name.replace("_", "-")}}."
@@ -20,27 +23,38 @@ Example:
2023
2124
2225@click.command(
23- cls=Generator,
24- # Or use repository address
25- template=os.path.dirname(__file__),
26- category="Custom" ,
26+ # Using ``GeneratorCommand`` class is not required.
27+ # It only provides you with alias, category and some help formatting utils.
28+ # You can use ``click.Command`` should you choose.
29+ cls=GeneratorCommand ,
2730 help=cmd_help,
2831 short_help=cmd_short_help,
32+ # Define alias short-cut for more efficient invocation
33+ alias="foo",
34+ # Define category under which generator should be printed in ``fastapi-mvc generate`` CLI command help page.
35+ category="Custom",
2936)
3037@click.argument(
3138 "NAME",
3239 required=True,
3340 nargs=1,
3441)
35- @click.pass_context
36- def {{generator_name}}(ctx, name):
37- # You can access Generator class object instance for this command via click.Context
38- # https://click.palletsprojects.com/en/8.1.x/api/?highlight=context#click.Context.command
39- ctx.command.ensure_project_data()
42+ def {{generator_name}}(name: str) -> None:
43+ """Define {{generator_name}} generator command-line interface.
44+
45+ Args:
46+ name (str): Given name to greet.
47+
48+ """
49+ project_data = require_fastapi_mvc_project()
4050
4151 data = {
42- "project_name": ctx.command. project_data["project_name"],
52+ "project_name": project_data["project_name"],
4353 "name": name.lower().replace("-", "_"),
4454 }
4555
46- ctx.command.run_copy(data=data)
56+ copier.run_copy(
57+ src_path=os.path.dirname(__file__), # Or use git repository
58+ data=data,
59+ answers_file=ANSWERS_FILE,
60+ )
0 commit comments