LinuxCommandLibrary

cookiecutter

Generate projects from templates

SYNOPSIS

cookiecutter TEMPLATE_URL [--no-input] [--checkout REVISION] [--output-dir OUTPUT_DIRECTORY] [--config-file CONFIG_FILE] [--default-config] [--replay] [--overwrite-if-exists] [--accept-hooks] [--directory DIRECTORY] [--verbose] [--debug]

PARAMETERS

TEMPLATE_URL
    The URL or path to the cookiecutter template repository or directory. This can be a local path, a git repository URL, or a shorthand notation (e.g., github.com/user/repo).

--no-input
    Do not prompt for parameters and only use cookiecutter.json file content.

--checkout REVISION
    Checkout a specific tag, branch or commit ID in the template repository.

--output-dir OUTPUT_DIRECTORY
    The directory where the generated project will be created. Defaults to the current directory.

--config-file CONFIG_FILE
    Path to a custom configuration file to override default settings.

--default-config
    Do not load a config file. Use defaults instead.

--replay
    Do not prompt for parameters and only use information from the replay file.

--overwrite-if-exists
    Overwrite the contents of the output directory if it already exists.

--accept-hooks
    Accept all pre- and post-generation hooks without prompting.

--directory DIRECTORY
    Directory within the template repository that contains the cookiecutter.json file. Useful when the template is not at the root of the repository.

--verbose
    Show verbose output messages.

--debug
    Show debug output messages.

DESCRIPTION

Cookiecutter is a command-line utility that creates projects from project templates, also known as "cookiecutters". A cookiecutter is a template directory structure, often containing placeholders for variables that are replaced during project generation. This allows developers to quickly scaffold new projects with a consistent structure, including files for documentation, testing, and dependency management. Cookiecutter supports various template sources including local directories and remote repositories (e.g., GitHub, GitLab, Bitbucket).
It streamlines the setup process, reducing the time and effort required to start a new software project. Cookiecutter templates can include Jinja2 templating for complex logic, and pre/post generation hooks allowing to customize the process even further. The result is a well-organized project that can be immediately built upon, promoting best practices and standardization across projects.

CAVEATS

Cookiecutter requires Python to be installed. The template should follow the cookiecutter template format. Overwriting an existing directory can lead to data loss.

TEMPLATE STRUCTURE

A Cookiecutter template is a directory containing a cookiecutter.json file. This JSON file defines the variables to be prompted for, along with default values. The template also includes directories and files that are copied to the output directory, with variable placeholders rendered using Jinja2.

HOOKS

Cookiecutter supports pre- and post-generation hooks. These are shell scripts that run before and after the project is created. They allow for advanced customization, such as installing dependencies, initializing a Git repository, or performing code formatting.

HISTORY

Cookiecutter was created to automate project setup, eliminating repetitive manual tasks. It became popular within the Python community and has since expanded to support various languages and project types. Its ease of use and extensibility have contributed to its widespread adoption.

SEE ALSO

mkproject(1), tox(1)

Copied to clipboard