You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched the issues of this repo and believe that this is not a duplicate.
Feature Request
Currently, implementing custom generators might be confusing since one needs to access "self" via click.Context class object instance for a given generator command:
importclickfromfastapi_mvcimportGenerator
...
@click.command(cls=Generator,# Or use repository addresstemplate=os.path.dirname(__file__),category="Custom", ...alias="foo",)@click.argument("NAME",required=True,nargs=1,)@click.pass_contextdeffoobar(ctx, name):
ctx.command.ensure_project_data()
data= {
"project_name": ctx.command.project_data["project_name"],
"name": name.lower().replace("-", "_"),
}
ctx.command.run_copy(data=data)
Not only this might be misleading but it does not guarantee that ctx.command will be an instance of a Generator class. Moreover, this won't pass type checking (that will be added soon). IMHO, an approach where generators utilities are coupled with Generator command line interface class not only breaks the single responsibility principle but also adds an unnecessary layer of complexity. In the end, most of the utility methods were static anyways. Lastly, I also think it's better to use copier directly rather than via wrapper.
This refactor will be a bit chaotic due to limited time resources, and some degree of unknown. General plan:
Refactor Generator.poetry_path method to shell utils
Refactor generator utilities into a separate submodule
Refactor constants into separate submodule
Refactor Generator.insert_router_import method into the controller generator
Rename Generator class to GeneratorCommand
Drop copier wrappers
Update docs
Update tests
Anything else in order to facilitate this change
Lastly, a copier-generator template will have to be updated to work with the new API for creating generator's CLIs.
The text was updated successfully, but these errors were encountered:
Feature Request
Currently, implementing custom generators might be confusing since one needs to access "self" via
click.Context
class object instance for a given generator command:Not only this might be misleading but it does not guarantee that
ctx.command
will be an instance of aGenerator
class. Moreover, this won't pass type checking (that will be added soon). IMHO, an approach where generators utilities are coupled withGenerator
command line interface class not only breaks the single responsibility principle but also adds an unnecessary layer of complexity. In the end, most of the utility methods were static anyways. Lastly, I also think it's better to usecopier
directly rather than via wrapper.This refactor will be a bit chaotic due to limited time resources, and some degree of unknown. General plan:
Generator.poetry_path
method to shell utilsGenerator.insert_router_import
method into the controller generatorGenerator
class toGeneratorCommand
copier
wrappersLastly, a
copier-generator
template will have to be updated to work with the new API for creating generator's CLIs.The text was updated successfully, but these errors were encountered: