Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
async-autocomplete-cli
Advanced tools
Readme
A CLI prompt that allows the user to select from a list of choices, where the choices are fetched asynchronously (e.g. from a request to a remote server). The user can type filter text and new choices matching that filter text will be fetched.
Based upon prompts
; this basically a stripped-down fork of that repo.
npm i --save async-autocomplete-cli
const { asyncAutocomplete } = require('async-autocomplete-cli')
async function go() {
const instance = await asyncAutocomplete({
message: 'Select an AWS EC2 Instance',
suggest: async (input, cancelationToken, yield) => {
const results = []
if (!input) {
// getRecentSelectedInstances not implemented in this example.
results.push(...(await getRecentSelectedInstances()))
yield(results)
}
const Filters = []
if (input)
Filters.push({
Name: 'tag:Name',
Values: [`*${input}*`],
})
const args = { MaxResults: 100 }
if (Filters.length) args.Filters = Filters
const request = ec2.describeInstances(args)
cancelationToken.on('canceled', () => request.abort())
if (cancelationToken.canceled) return []
const { Reservations } = await request.promise()
for (const { Instances } of Reservations || []) {
for (const Instance of Instances || []) {
const { InstanceId, Tags = [] } = Instance
const name = (Tags.find(t => t.Key === 'Name') || {}).Value
results.push({
title: `${InstanceId} ${name || ''}`,
value: Instance,
initial: !results.length,
})
}
}
if (!results.length) {
results.push({
title: `No matching EC2 Instances found${
input ? ` with name starting with ${input}` : ''
}`,
})
}
return results
},
})
}
go()
asyncAutocomplete(options)
The suggest
function will be called with:
cancelationToken
. This is an EventEmitter
that will event 'canceled'
when the user input has changed.
It also has a canceled
property that is initially false
and becomes true
when the user input has changed.
You must handle the 'canceled'
event if you want choices for the latest user input to load ASAP.yield
function you can call with an array of choices objects [{ title, value }, ...]
. You can also return the
final choices, but calling this function
allows you to change the choices even if the user input remains the same. For example, you might want to save what the user has recently selected to a local
file, and show the recent selections immediately while waiting to load other choices from the server.Param | Type | Description |
---|---|---|
message | string | Prompt message to display |
suggest | function | Function to fetch choices |
limit | number | Max number of results to show. Defaults to 10 |
style | string | Render style (default , password , invisible , emoji ). Defaults to 'default' |
clearFirst | boolean | The first ESCAPE keypress will clear the input |
FAQs
tool for prompting the user to select from a list of choices, where the choices are fetched asynchronously, and new choices are fetched as the user types
The npm package async-autocomplete-cli receives a total of 4 weekly downloads. As such, async-autocomplete-cli popularity was classified as not popular.
We found that async-autocomplete-cli demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.