Using and Mastering Cookiecutter Transcripts
Chapter: Creating Cookiecutter templates
Lecture: Concept: Required values

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Blank defaults make a lot of sense, sometimes you just don't want to have a value unless they type it in,
0:07 like you have no idea what the default could be, or maybe you want to have a blank one and indicate you must enter this,
0:13 there is no choice but to type here something that makes sense for your project. So let's look at an example.
0:20 We come here and we run this cookiecutter template, maybe it's going to come along and ask your name and your favorite color,
0:26 alright, well how do we make this like a required value. Well, if we just wanted blank with no defaults,
0:32 and it's going to be empty unless they put something in, this is fine, all we have to do is have our json file have empty value
0:39 and you have an empty non default, but what it really means is the default is an empty string, so it still could go a little bit wrong.
0:47 We saw that we tried to have some sort of keyword here like hey let's try required and of course, we put required over there,
0:54 but that doesn't really do anything, so we saw that it will just use required. What is required to make this keyword work or something like that is
1:01 writing a little bit of Python code in what is called a pre generation hook, we're going to talk about hooks at the end of this chapter,
1:09 but a pre generation hook is code that runs after the data is collected here, but before it actually executes the process that creates the directories,
1:18 copies the files, does the replacement, and you'll get a look at what is called the context, and this context is all the values,
1:23 the keys and the values, basically listed in cookiecutter.json, so we could say if the value favorite color is still required,
1:30 or if it doesn't seem like some kind of color we could say no, no, we're not going to run, we're going to cancel this,
1:37 tell you you need to enter a favorite color, it's not amazing, but that's what it is.

Talk Python's Mastodon Michael Kennedy's Mastodon