Using and Mastering Cookiecutter Transcripts
Chapter: Advanced Cookiecutter usage
Lecture: Setting up default values

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Okay so here we are in chapter 4, in the source control area.
0:04 Let's go ahead and try cookiecutter cookiecutter-bottle
0:08 You can see it's asking various things, like these are just the defaults,
0:11 let's see how we can change these, so what we can do is
0:15 we can actually create a default file
0:17 and the format of this file is going to be a YAML file.
0:20 And you can put it wherever you want and then you point to it in Cookiecutter,
0:24 but I am going to put it in that Cookiecutters folder
0:27 because that's where I go for my Cookiecutter stuff.
0:29 So you can call this whatever you want, it doesn't matter,
0:32 there is no like convention around naming,
0:34 so I am going to call mine defaults-kennedy.yaml,
0:36 we open this up and what we can put in here is a couple of things,
0:39 so we can start out by saying our default_context
0:43 and then we set properties by doing colon here,
0:46 so we can set our full name, go and set our email here,
0:49 now there is no scheme or anything here, it just happens to be
0:53 if the template asks you for full_name it's going to look in here
0:58 to see if there is a value and use this instead of their default.
1:01 So you might have fullname, you might have also fullName, right,
1:06 you might have to enter these things several times,
1:08 but once we have this here, we can save this
1:11 and we can run the same thing with specifying the config file.
1:23 Like so, let's see what we got, oh look, what is your full_name,
1:26 my full name is Michael, and my email is this,
1:29 and my GitHub username is this, oh so refreshing.
1:31 And of course we probably don't have a default project name
1:34 or app name or things like that, or a really project description,
1:37 so these I don't really know how to set defaults for these
1:39 unless you create almost exactly the same app all the time,
1:42 so that's cool, so we can do this, now it would be great if I just ran it like this,
1:46 I don't have to say the config file, it would give me my values but clearly,
1:49 it's not, so there is one final step for us to do, we need to go into our profile,
1:54 that starts our shell, and set an environment variable,
1:58 now if you're on Windows, you have to do this in a slightly different way,
2:01 you just set an environment variable under the "Advanced system settings".
2:04 Okay, but for now, let's do it on my Mac
2:07 and then I can show you how to do it on Windows as well.
2:10 So we're going to manage our ~/.profile here and notice,
2:13 I've got my path and my prompt but let's put it at the bottom,
2:16 what we want to do is we just want to put export statement
2:19 that says the Cookiecutter config that you use is here,
2:24 /Users/screeencaster/.cookiecutters/defaults-kennedy.yaml
2:29 alright, so if we go back over here, and we try to run this,
2:33 it's still the same, why, because we have to exit and start over.
2:39 Now, let's try one more time, okay,
2:42 so we're going to say cookiecutter cookiecutter-bottle hit enter,
2:47 and perfect, it's now taken our defaults, so what we had to do is
2:52 we had to create that YAML file with our defaults,
2:54 and then we had to set an environment variable here
2:57 the name of the environment variable is COOKICUTTER_CONFIG all caps
3:01 and then just point at whatever the path is, so let's go ahead and roll with this,
3:05 enter, enter, enter, oh, that felt good, I'll call this Second Bottle App,
3:11 let's just call it secondbottle and a demo of default values,
3:15 off it goes, and there we know we have our secondbottle created,
3:20 this time, using our default values.