Linux command
cookiecutter 命令
网络
复制后可按需替换文件名、目录或参数。
常用示例
Create project from template
cookiecutter [https://github.com/user/template]
Create from local template
cookiecutter [/path/to/template]
Create without prompts
cookiecutter --no-input [template]
Override template variables
cookiecutter [template] [project_name]="[MyProject]"
List installed templates
cookiecutter --list-installed
Replay last creation
cookiecutter --replay [template]
Output to specific directory
cookiecutter -o [/output/path] [template]
说明
cookiecutter is a command-line utility for creating projects from templates, eliminating the need to manually set up boilerplate code and project structure. It takes a template directory (local or from a Git repository) and prompts for configuration values, then generates a complete project with those values substituted throughout. Templates use Jinja2 syntax for variable substitution in both filenames and file content. For example, a template might prompt for "project_name" and use it to create directories, populate setup files, and customize code comments. This ensures consistency across projects while allowing customization. The tool has spawned a large ecosystem of community templates for frameworks like Django, Flask, React, and many others. cookiecutter is language-agnostic and can template any type of project. It supports advanced features like conditional file inclusion, pre/post-generation hooks, and replay files for reproducing previous configurations. The tool has become a standard in Python development and influenced similar tools in other ecosystems.
参数
- -o, --output-dir _path_
- Output directory for generated project.
- --no-input
- Use default values without prompting.
- -c, --checkout _branch_
- Git branch or tag to checkout.
- -v, --verbose
- Print debug information.
- --replay
- Use previously entered values.
- --replay-file _file_
- Use values from specified file.
- -f, --overwrite-if-exists
- Overwrite existing output directory.
- -s, --skip-if-file-exists
- Skip files that already exist.
- --list-installed
- List installed templates.
- --config-file _file_
- User configuration file.
FAQ
What is the cookiecutter command used for?
cookiecutter is a command-line utility for creating projects from templates, eliminating the need to manually set up boilerplate code and project structure. It takes a template directory (local or from a Git repository) and prompts for configuration values, then generates a complete project with those values substituted throughout. Templates use Jinja2 syntax for variable substitution in both filenames and file content. For example, a template might prompt for "project_name" and use it to create directories, populate setup files, and customize code comments. This ensures consistency across projects while allowing customization. The tool has spawned a large ecosystem of community templates for frameworks like Django, Flask, React, and many others. cookiecutter is language-agnostic and can template any type of project. It supports advanced features like conditional file inclusion, pre/post-generation hooks, and replay files for reproducing previous configurations. The tool has become a standard in Python development and influenced similar tools in other ecosystems.
How do I run a basic cookiecutter example?
Run `cookiecutter [https://github.com/user/template]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -o, --output-dir _path_ do in cookiecutter?
Output directory for generated project.