Skip to content

Command manager

Victor Shelepen edited this page Jul 20, 2021 · 8 revisions
// import { runCommand, extractValue } from 'console-command-manager' // @todo Uncomment at the real case.
import { runCommand, extractValue } from '../src/index'

(async function () {
  await runCommand(
    [
      {
        name: 'print',
        title: 'Prints values',
        handler: async ({request, injection: {console, DateFactory}}) => {
          const format = extractValue(request.args, 'format', 'not_set')
          console.log(`I am printing you text  ' ${request.values.join(' ')}  at ${new DateFactory()} ' format - ${format}`)
        }
      },
    ],
    {
      DateFactory: Date
    },
    process.argv.slice(2)
  )
})()

The command line

npx babel-node ./example/commander.js print --format="A4" some text

Produces such lines

I am printing your text  ' some text  at Fri Mar 20 2020 18:11:19 GMT+0200 (Eastern European Standard Time) ' format - A4

Check for workable example here

Clone this wiki locally