Skip to content
This repository has been archived by the owner on Sep 12, 2019. It is now read-only.

Add name flag to functions create #17

Merged
merged 2 commits into from
Mar 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,23 @@ netlify plugins:link .

Now you're both ready to start testing netlify dev and to contribute to the project.

## Functionality
## Functionality Notes

- `netlify dev` now supports both `_redirects` and `netlify.toml` for redirects and has the same logic around loading order as our system (_redirects, toml in public folder, toml in base)
- `netlify dev` can be configured for projects we don’t detect out of the box with a `[dev]` block in the toml file
- `netlify dev` now supports both `_redirects` and `netlify.toml` for redirects and has the same logic around loading order as our system (\_redirects, toml in public folder, toml in base)
- `netlify dev` can be configured for projects we don’t detect out of the box with a `[dev]` block in the toml file

## `netlify functions:create`

Create a new function from a given template.

Examples:

```
netlify functions:create
netlify functions:create hello-world
netlify functions:create --name hello-world
netlify functions:create hello-world --dir

```

You can just call `netlify functions:create` and the prompts will guide you all the way, however you can also supply a first argument to name the function. By default it creates a single file, however you can also use a `--dir` flag to create a function as a directory.
21 changes: 17 additions & 4 deletions src/commands/functions/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class FunctionsCreateCommand extends Command {
console.error('an error occurred retrieving template code, please check ' + templatePath, err)
process.exit(0)
}
const name = await getNameFromArgs(args, path.basename(templatePath, '.js'))

const name = await getNameFromArgs(args, flags, path.basename(templatePath, '.js'))

this.log(`Creating function ${name}`)

Expand Down Expand Up @@ -93,9 +94,15 @@ FunctionsCreateCommand.args = [

FunctionsCreateCommand.description = `create a new function locally`

FunctionsCreateCommand.examples = ['netlify functions:create hello-world']
FunctionsCreateCommand.examples = [
'netlify functions:create',
'netlify functions:create hello-world',
'netlify functions:create --name hello-world',
'netlify functions:create hello-world --dir'
]

FunctionsCreateCommand.flags = {
name: flags.string({ char: 'n', description: 'function name' }),
functions: flags.string({ char: 'f', description: 'functions folder' }),
dir: flags.boolean({
char: 'd',
Expand All @@ -105,8 +112,14 @@ FunctionsCreateCommand.flags = {
module.exports = FunctionsCreateCommand

// prompt for a name if name not supplied
async function getNameFromArgs(args, defaultName) {
let { name } = args
async function getNameFromArgs(args, flags, defaultName) {
if (flags.name && args.name) throw new Error('function name specified in both flag and arg format, pick one')
let name
if (flags.name && !args.name) name = flags.name
// use flag if exists
else if (!flags.name && args.name) name = args.name

// if neither are specified, prompt for it
if (!name) {
let responses = await inquirer.prompt([
{
Expand Down