Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: Googleform Prompt Documentation #247

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
76 changes: 76 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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),

<!-- Example: Google Form Prompt -->

```js
const Enquirer = require('enquirer');
const GoogleFormPrompt = require('prompt-google-form');

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));
```
<br>

## ❯ Key Bindings
Expand Down