Search code examples
pythoncookiecutter

How do I implement a cookiecutter project with custom shortcuts for certain commands?


I am developing a cookiecutter template for LaTeX projects. However, I would like to implement a CLI that acts as a shortcut for certain commands. For example, the command

cookiecutter --no-input --replay-file ~/.cookiecutters/cookiecutter-latex/style1.json

could also be executed using the command

customtex style1

I had thought of making a python package that implements the CLI and also contains the template, so that the customtex commands (the name of the package) use the cookiecutter contained in the package source files. This way, users could also simply download the template and use it as normal.

I would like to know if this is the best way to implement what I want or if you can think of a better way to do this. I would also like to know what problems I could have doing it this way.

Thanks in advance.


Solution

  • You've got a couple of ways you can do it, and you've hit on both.

    Embedding cookiecutter in a CLI is pretty common. Databricks has a tool called "dbx" that has an embedded cookiecutter template in it that it uses to generate new projects. So that's a reasonable way to go.

    You can also use post and pre hooks to modify behavior. My python template (Rob's Awesome Python Template) uses post hooks to modify the output based off of the arguments passed in by the user. This allows people to use Cookiecutter directly without installing anything else.