From dfaf9a68ae47f9b37c43c886ca2732db2c35b102 Mon Sep 17 00:00:00 2001 From: Aditya Vyas Date: Tue, 7 Jan 2020 21:59:10 +0530 Subject: [PATCH 1/2] Google Form Prompt Documentation --- README.md | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/README.md b/README.md index 79097114..4893c376 100644 --- a/README.md +++ b/README.md @@ -1532,7 +1532,83 @@ let answers = await enquirer.prompt([ } ]); ``` +## ❯ Google Form Prompt +**How do I create a custom form prompt?** + +Custom prompts are created by extending either: + +* Enquirer's `Form` class +* one of the built-in [prompts](#-prompts), + + + +```js +const Enquirer = require("enquirer"); +const GoogleFormPrompt = require("../index.js"); + +const enquirer = new Enquirer(); +enquirer.register("google", GoogleFormPrompt); + +enquirer + .prompt([ + { + type: "select", + name: "form", + message: "Which Form Would you like to fill out?", + choices: [{ + value: '1FAIpQLSdniaX5nAjywbvnT9tQp1OTryh7148Lkl5LnvJV1mBOy1QXdA', + message: 'Contact Form' + },{ + value: '1FAIpQLSfb_pdS57UJTS1qKaKfSLoDs9pudHLbNbkpp74kdpUYoEKz9Q', + message: 'T-Shirt Form' + },{ + value: '1FAIpQLSd5YEpcRFJAE47OuvHyI6equ66DEspA9S2AZHCafhokHUbjWg', + message: 'Event Form' + }] + }, + { + name: "Google Form", + message: "Please provide the information:", + formId(state){ + return state.answers.form; + }, + type: "google" + } + ]) + .then(res => console.log(res)) + .catch(err => console.log(err)); +``` + +If you want to be able to specify your prompt by `type` so that it may be used alongside other prompts, you will need to first create an instance of `Enquirer`. + +```js +const Enquirer = require('enquirer'); +const enquirer = new Enquirer(); +``` + +Then use the `.register()` method to add your custom prompt. + +```js +enquirer.register('google', GoogleFormPrompt); +``` + +Now you can do the following when defining "**formId**". +Here we are taking **formId** through Command Line Arguments + +```js +const GoogleFormPrompt = require('./index.js'); + +const prompt = new GoogleFormPrompt({ + name: "Google Form", + message: "Please provide the information:", + formId: process.argv[2], +}); + +prompt.run() +.then(res => console.log(res)) +.catch(err => console.log(err)); +```
## ❯ Key Bindings From 0792d32bb4b8e9d5a790b40e20f97ef5d6dbc592 Mon Sep 17 00:00:00 2001 From: Aditya Vyas Date: Sun, 19 Jan 2020 17:06:12 +0530 Subject: [PATCH 2/2] Documentation update for google form --- README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 4893c376..166f1362 100644 --- a/README.md +++ b/README.md @@ -1544,18 +1544,18 @@ Custom prompts are created by extending either: ```js -const Enquirer = require("enquirer"); -const GoogleFormPrompt = require("../index.js"); +const Enquirer = require('enquirer'); +const GoogleFormPrompt = require('prompt-google-form'); const enquirer = new Enquirer(); -enquirer.register("google", GoogleFormPrompt); +enquirer.register('google', GoogleFormPrompt); enquirer .prompt([ { - type: "select", - name: "form", - message: "Which Form Would you like to fill out?", + type: 'select', + name: 'form', + message: 'Which Form Would you like to fill out?', choices: [{ value: '1FAIpQLSdniaX5nAjywbvnT9tQp1OTryh7148Lkl5LnvJV1mBOy1QXdA', message: 'Contact Form' @@ -1568,12 +1568,12 @@ enquirer }] }, { - name: "Google Form", - message: "Please provide the information:", + name: 'Google Form', + message: 'Please provide the information:', formId(state){ return state.answers.form; }, - type: "google" + type: 'google' } ]) .then(res => console.log(res)) @@ -1593,15 +1593,15 @@ Then use the `.register()` method to add your custom prompt. enquirer.register('google', GoogleFormPrompt); ``` -Now you can do the following when defining "**formId**". +Now you can do the following when defining '**formId**'. Here we are taking **formId** through Command Line Arguments ```js const GoogleFormPrompt = require('./index.js'); const prompt = new GoogleFormPrompt({ - name: "Google Form", - message: "Please provide the information:", + name: 'Google Form', + message: 'Please provide the information:', formId: process.argv[2], });