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

Commit

Permalink
Merge pull request #17 from netlify/add-name-flag-to-functions-create
Browse files Browse the repository at this point in the history
Add name flag to functions create
  • Loading branch information
swyxio authored Mar 16, 2019
2 parents b650db7 + 4a7ed2a commit ecb0208
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
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

0 comments on commit ecb0208

Please sign in to comment.