cruft / cruft

Allows you to maintain all the necessary cruft for packaging and building projects separate from the code you intentionally write. Built on-top of, and fully compatible with, CookieCutter.
https://cruft.github.io/cruft/
MIT License
1.23k stars 89 forks source link

Cruft doesn't allow config from existing cookiecutter.json (?) #171

Open bullyrooks opened 2 years ago

bullyrooks commented 2 years ago

I have a github template for cookiecutter based spring boot projects here

I use github template to create a new repo populated with the template. I have a github action workflow triggered off changes to cookiecutter.json which will execute cookiecutter (currently works). This allows me to modify the 'default' values in an automated way so I don't have to interact with cookiecutter (service name, github repo, etc...).

Cookie cutter accepts the cookiecutter.json file via command line and everything is fine.

However, cruft doesn't appear to allow me to override the cookiecutter.json file from the template url. Whether I use create or link, it will always use the cookiecutter.json file from the template (which has the default values).

this doesn't work (from a copy of the template project) $ cruft create --config-file ./cookiecutter.json --no-input --output-dir ./cruft-temp https://github.com/bullyrooks/spring-microservice-template

Am I using config-file incorrectly? Is this not (currently) allowed by cruft?

My current workaround is edit .cruft.json after I run cruft... but I would rather tell cruft where my overrides are before I generate instead of the workarounds that I currently have to use.

bullyrooks commented 2 years ago

Here's a branch I created off my template https://github.com/bullyrooks/spring-microservice-template/tree/cruft-test

I ran the command above cruft create --config-file ./cookiecutter.json --no-input --output-dir ./cruft-temp https://github.com/bullyrooks/spring-microservice-template

with the updates to cookiecutter.json (also in this commit). You can see that .cruft.json has the original cookiecutter.json values.

bullyrooks commented 1 year ago

Just bumping this. When I do cruft update, It overwrites my cruft json with values from the 'original' cookiecutter template. I would really like to keep my project values (from cookiecutter.json)

eperdeme commented 1 year ago

If you're wanting to pass in input parameters at creation then it's as follows;

cruft create  --no-input --output-dir ./cruft-temp https://github.com/bullyrooks/spring-microservice-template --extra-context '{"project_slug":"slugs","project_name":"eks","aws_account_id":"838383"}'

I don't believe you can pass in a file as the variable input, so you need to take your JSON from cookiecutter.json and convert it to single like then wrap it in single quotes.

The --config-file is to pass in user YAML config for cookiecutter- https://cookiecutter.readthedocs.io/en/1.7.2/advanced/user_config.html