You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

super-cli

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

super-cli

Super-CLI is a micro framework for command line tools.

1.0.1
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

Super-CLI

npm version Build Status Standard - JavaScript Style Guide

Super-CLI is a micro framework for creating command line tools in node. The goal with Super-CLI is to have a simple and powerful API, which enables you to create beautiful CLI programs with minimal effort.

A Super-CLI script will have a structure like below.

my-script command [options, ...] [arguments, ...]

Install

npm install super-cli -—save

Usage

To get started you have to require the super-cli module and register your commands. Remember to set the environment to node at the top of the script #!/usr/bin/env node and make your script executable chmod a+x my-script.

#!/usr/bin/env node

const SuperCLI = require('super-cli')

const cli = new SuperCLI()

cli.on('my-command', arg => {
  console.log(arg)
})

Register commands

Commands are simply registered like below and arguments are automatically parsed to the callbacks as function arguments. If your CLI program has a lot of commands, it would be a great idea to move the command callbacks into seperate files.

cli.on('my-command', (arg1, arg2, ...) => {
  // do something
})

Check for options

cli.option('-h', '--help') // will return true if set
cli.option('-l=', '--lastname=') // will return the value of --lastname if set

Run command

Trigger a command from within the script.

cli.run('my-command')

Prompt user for input

cli.prompt('My question:').then(answer => console.log(answer))

Catch all commands

This will run if no registered command was triggered.

cli.on('*', (...args) => {
  console.log(args)
})

Listen for data on stdin

cli.stdin(data => console.log(data))

Write data to stdout

// you can use
console.log('message')
// or
cli.stdout('message')

On exit

cli.on('exit', () => {
  // this event will fire on cli exit or termination
})

Exit cli

cli.exit() // will close the cli and fire the exit event

Keywords

cli

FAQs

Package last updated on 27 Dec 2016

Did you know?

Socket

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