Using and Mastering Cookiecutter Transcripts
Chapter: Creating Cookiecutter templates
Lecture: Default values and required values
Login or
purchase this course
to watch this video and the rest of the course contents.
0:01
Let's take a moment and focus on required values. Basically making sure that user enters something. Now, we're going to try and see that we at least
0:12
can get to like a blank value thing, but we won't really be able to solve this problem until we look at one more feature later on,
0:18
but let's give it a shot here and then we'll come back and look at it. So I've done a little bit of reorganizing here, I've saved off the work
0:26
we have done so far into cookiecutter-colors-v1 and now, this one I've changes a little bit, notice since that it had been project name
0:33
we have project slug here, and over in the json, I've added that little trick to take the project name and generate a slug from it,
0:41
so that we have a little more reliability, for the file or the project, the folder that we generate because,
0:48
if we have things like colons and slashes and stuff it's not going to work out so well for us.
0:53
So let's suppose that we want creator to be a required value, maybe we could start like this, let's suppose those two have to be required values,
1:02
one possibility we say let's put in nothing and see what happens here,
1:07
so if I run this, cookicecutter cookiecutter-colors it's going to ask some questions, my project I'll say the best ever and you can see the best ever
1:15
how cool is that, right, so we'll take that default and creator, well, what we would like for it to do is say you must specify a creator name,
1:21
you must specify color name, and now if we open up the best ever, like this, you can see up here at the top where it used to say blue,
1:32
it's just empty, right, so much for required value, because, these empty values just went in as empty values.
1:39
Well, we can try one more thing, maybe we can have something like required here, yeah. that is probably going to do it, let's try one more time,
1:47
run the same code here, like this, alright, we'll just take the defaults blank and required, no, still nothing.
1:55
Although, in a slightly better way, we should be able to see that our blue is now required.
2:02
Okay, so this is not working, but the one half that we do want is we should be able to use either of these, we want to create a system
2:08
where we can say creator is blank, and somehow maybe know that that is required, we want to be able to say favorite_color=required
2:16
and they are not allowed to enter, something else. we could see that we could give them a choice here,
2:22
and then they would have to choose from the list, like blue yellow green red, but if we want the full rainbow, the entire spectrum of colors,
2:29
well, we're going to have to do something more interesting than that.