In the previous article, I wrote about project name validation. In this article, let’s look at more code from index.ts
if (program.example === true) {
console.error(
'Please provide an example name or url, otherwise remove the example option.'
)
process.exit(1)
}
program.example reminds of accessing options passed in via the cli
example is an option as shown below:
// https://www.npmjs.com/package/commander#options// -e// https://github.com/vercel/next.js/tree/canary/packages/create-next-app#non-interactive.option( '-e, --example [name]|[github-url]', ` An example to bootstrap the app with. You can use an example name from the official Next.js repo or a GitHub URL. The URL can use any branch and/or subdirectory `)
Pass it as npx create-my-app -e, because it needs url when there is no url provided, the following error is thrown
As I look at the more lines of code, I see that there is safeguarding in place for options submitted, for example, for project name and now for example.
Take the user input and importantly validate it before proceeding further.