Socket
Socket
Sign inDemoInstall

list-selector-cli

Package Overview
Dependencies
81
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    list-selector-cli

(Hopefully) useful little commandline interface for selecting items from a list, inspired by the git-add interactive interface.


Version published
Weekly downloads
8
increased by166.67%
Maintainers
1
Install size
3.36 MB
Created
Weekly downloads
 

Readme

Source

Git-style interactive list selector for Node CLI apps

  • Does one thing: Lets the users of your NodeJS app interactively select/de-select items from a list by indices and ranges on the commandline.

  • Familiar "UI" -- to GitHubbers at least! Same interface as the trusty "git add --interactive"

  • Brain-dead simple to use in your project

  • Options can be any array of toString-able things

  • Get the user's response in a callback OR a jQuery-style promise

Example: Let's make a sandwich

Probably better for selecting filepaths, but I'm hungry right now so...

Let's choose the toppings on your sandwich via CLI.

What you do

  1. Install from NPM:
npm install list-selector-cli`
  1. Require it in your project:
var cliselect = require("list-selector-cli");
  1. Pick an array of options:
var options = ["lettuce", "tomatoes", "spinach", "ham"];
  1. Create your list:
var sandwichChoice = new cliselect(options);
  1. Prompt the user: console.log("What would you like on your sandwich?")

  2. Let them interactively choose their options and handle their response

  • In a callback:
sandwichChoice.prompt(function(selection) { /** do something **/ });
  • Or with a promise:
var promise = sandwichChoice.prompt();
promise.done(function(selection) { /** do something **/ });

What you get

$ node examples/sandwich.js
What would you like on your sandwich?

 0:  lettuce
 1:  tomatoes
 2:  spinach
 3:  avocado
 4:  ham
 5:  bacon
 6:  oil
 7:  vinegar

Update selection (blank to accept)>>: 

Hmm... All the veggies and some oil, please.

Update selection (blank to accept)>>: 0-4,6
*0:  lettuce
*1:  tomatoes
*2:  spinach
*3:  avocado
*4:  ham
 5:  bacon
*6:  oil
 7:  vinegar
Update selection (blank to accept)>>:

Crap, I don't eat ham. De-ham the sandwich, plz.

Update selection (blank to accept)>>:-4
-4
*0:  lettuce
*1:  tomatoes
*2:  spinach
*3:  avocado
 4:  ham
 5:  bacon
*6:  oil
 7:  vinegar
Update selection (blank to accept)>>:

Eat-able? Yes. <Enter>

[ 'lettuce', 'tomatoes', 'spinach', 'avocado', 'oil' ]

Totally pitching a commandline interface to Subway...

Maybe ssh.subway.com: "open 8am to 9pm and 24 hrs a day on port 22..." :-)

Keywords

FAQs

Last updated on 04 Sep 2014

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc