0.1.1 • Published 6 years ago

consoless v0.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

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()
0.1.1

6 years ago

0.1.0

6 years ago