Using and Mastering Cookiecutter Transcripts
Chapter: Advanced Cookiecutter usage
Lecture: The full CLI
Login or
purchase this course
to watch this video and the rest of the course contents.
0:01
Let's look at the full command line interface. We're going to dig into Cookiecutter's extra features and we'll look at how each one of them works
0:11
and how you can get the most out of them. Let's just start with a quick overview, so cookiecutter --help
0:16
and it's going to say here is the usage, right, we're going to create some kind of project as you know,
0:21
first thing, you can say V or lower case --version to get the version, that's easy you can say --no-input, now --no-input is really interesting,
0:30
each prompt that you see in that process that runs the template has a default,
0:35
so if you say --no-input it will ask no questions and just take all the defaults. The place that to me seems most useful is if you want to execute
0:45
a Cookiecutter template as part of a continuous integration, so you can just configure your CI build to run
0:52
with whatever the defaults are, and just say --no-input and it will just run and output the results and then maybe do unittests
0:59
or builds or whatever you're going to do against the result of running that template. You can say -c or --checkout to get alternate branches,
1:07
we've seen that we can run directly from GitHub repos or git repos in general, and often, there is multiple branches, maybe we want to run
1:15
a different branch for whatever reason, like we could be evolving our template and using the git flow
1:21
so we have a feature branch for some change, right, we can run that by saying -c branch name along with the url. So that's pretty cool.
1:30
Verbose, if you want to understand what Cookiecutter is doing, -v is great because it will show you all the things,
1:36
especially this is really helpful when you are building your own template
1:39
or working with your own sort of post processing code that will run across this, right, we have something called hooks that we'll look at later;
1:47
another thing you might want to do is enter some answer, some specific value that says you're on this template
1:53
but you want to do it over and over again, right, again, this is most helpful when you're doing some sort of template building,
1:59
right, I want to answer the questions this way and then see what happened,
2:03
delete, run it again, so you can say --replay and if you've run the template before,
2:07
it will just feed all the same answers, defaults or custom answers, whatever you put into the answers for those prompts
2:15
and then reexecute it, so this is really nice. Also, this could be useful for continuous integration as well.
2:21
-f again, if you want to blast away the files, you want to be really careful here, if you're just a regular user, and you are just running this,
2:29
this will erase whatever is there if there is a directory with the same name, so don't blow away your project, but if you know what you're doing,
2:35
if you're building a template or you're doing continuous integration,
2:37
that might be exactly what you want, so a little -f it will save a lot of trouble. You want to change where the files go, -o or --output-dir
2:46
Cookiecutter by default puts the generated project as a subdirectory right wherever you are,
2:52
your working directory so this will let you overwrite that. You can specify a configurations file, so if you run a lot of Cookiecuter templates
2:58
you are going to get tired of answering the question what is your name, what is your email, what is your GitHub account name, things like that,
3:05
so we can create this thing called a config file, put my email address is this, my GitHub account name is this, and then when Cookiecutter runs
3:14
it will look at this config file, if you pass it like this, and it will change those default prompts to be your default values,
3:20
not the default values out of the template, that is so nice. You can also say don't do that, don't run the configuration file,
3:28
run without it, you might be thinking well, if you're going to just put --config-file it will run it, but just omit that,
3:36
well, we'll see later that we can actually register a global config file for our user profile
3:42
and not have to pass this config flag or path or anything, it will just automatically find and always use it, which is definitely recommended.
3:49
But periodically you might want to say well what's this look like without my config file on a bare machine,
3:55
so --default-config you can get lots of debug output kind of like verbose and you can feed that to a file so great for debugging
4:02
maybe for continuous integration as well, not really sure about that but definitely good
4:07
if you want t try debug what you're working on and save it to a file. Anyone see this message -h