kickstart
kickstart copied to clipboard
Using a previous input as a default
Hi! Stumbled on this whilst looking through the cargo template
RFCs. From the docs, it's not obvious (at least for me) whether this is supported so I figured I'd just ask as it might be a good feature addition in future:
If I have a variable of "project", can I use the input the user provides in a default for another variable?
Here's an example of why, albeit a bit of a dumb one:
Let's pretend I want to generate a *_manifest.txt
file. If you name your project "my", I would generate "my_manifest.txt" unless you chose to override the name to "other_manifest.txt". So I'd be using the project
variable provided as the default for the manifest
variable (or whatever).
Is this currently possible?
Currently no. cookiecutters allows defaults to be templated so you can use previous questions results.
It would look like that in kickstart:
[[variables]]
name = "manifest_filename"
default = "{{project}}_manifest.txt"
prompt = "What is the name fo the manifest?"
This would only work for strings as kickstart uses the type of the default
variable to infer the type of values to expect but I think it covers 95% of the usecases.
It should be pretty easy to add if someone wants to do a PR!
@Keats ok cool, I might take a look at doing that. Is it definitely not supported? I took another look at the example and the cleanup uses a similar syntax to that, which makes me think it might work?
It is not supported, you can check the code in https://github.com/Keats/kickstart/blob/master/src/definition.rs#L116-L124 to verify
To get it to work, you would need to check if s
is a template or not. You can probably just always render it anyway, unlikely to cause issues and it is fast enough.
@Keats I propose a PR (#58) implementing this feature!