consoless

0.1.1 • Public • Published

consoless

A simple Node console library. Inspired by express, consoless aims to make nested console programs simpler and easier.

Features

  • Matches commands with simple regex-style expressions
  • Extracts params from commands
  • Nested commands - i.e. add specific listeners if a specific command is typed (see example below)
  • Global commands

Example usage

var cons = require('consoless')

var app = new cons()
app.on('delete [file]*', (input, app) => {
  console.log('are you sure you want to delete \'' + input.params.file + '\'?')
  app.on('yes', (input, app) => {
    console.log('file deleted')
    app.done(2) //this takes us back to the original routes - i.e. 'delete file'
    //go up two steps - going up by one gets us back to this listener
  })
  //anything else (routes are checked in order)
  app.on('*', (input, app) => {
    console.log('file not deleted')
    app.done(2)
  })
  app.listen()
})
app.on('version', (input, app) => {
  console.log('consoless version 0.1.1')
  app.done()
})
app.global('exit', (input, app) => {
  app.stop()
})
app.global('***', (input, app) => {
  console.log('command not recognised')
  app.listen()
})
app.listen()

Readme

Keywords

Package Sidebar

Install

npm i consoless

Weekly Downloads

1

Version

0.1.1

License

MIT

Last publish

Collaborators

  • maxsw