Skip to content

Commit

Permalink
Test fix. Documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
ViShell committed Mar 20, 2020
1 parent 76ee793 commit 319c7f8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
7 changes: 3 additions & 4 deletions example/boiler-plate.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
(async function() {
// const { runCLI } = require('console-command-manager') // @todo Uncomment at the real case.
const { runCLI } = require('../src/cli')
const { runCLI, extractValue } = require('../src/index')

runCLI('Hello!', [
{
name: 'print',
title: 'Prints values',
handler: async ({request, injection: { console, DateFactory } }) => {
console.log(`I am printing you - ${request.values.join(' --> ')} - now at ${new DateFactory()}`)

return true
const format = extractValue(request.args, 'format', 'not_set')
console.log(`I am printing you text ' ${request.values.join(' ')} at ${new DateFactory()} ' format - ${format}`)
}
},
],
Expand Down
7 changes: 3 additions & 4 deletions example/commander.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
(async function () {
// const { runCommand } = require('console-command-manager') // @todo Uncomment at the real case.
const { runCommand } = require('../src/cli')
const { runCommand, extractValue } = require('../src/index')
await runCommand(
[
{
name: 'print',
title: 'Prints values',
handler: async ({request, injection: {console, DateFactory}}) => {
console.log(`I am printing you - ${request.values.join(' --> ')} - now at ${new DateFactory()}`)

return true
const format = extractValue(request.args, 'format', 'not_set')
console.log(`I am printing you text ' ${request.values.join(' ')} at ${new DateFactory()} ' format - ${format}`)
}
},
],
Expand Down
7 changes: 6 additions & 1 deletion test/cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ const EventEmitter = require('events')
const { _console } = require('./helper')

describe('Commander', () => {
before(() => {
_console.clear()
})

it('Run commander', async () => {
await runCommand(
[
Expand All @@ -28,9 +32,10 @@ describe('Commander', () => {
})

describe('CLI', () => {
let readline, _console, cli
let readline, cli

before(() => {
_console.clear()
readline = new EventEmitter()
readline.close = function() {
this.isClosed = true
Expand Down
3 changes: 3 additions & 0 deletions test/helper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const _console = {
objects: [],
clear: function() {
this.objects = []
},
log: function(object) {
this.objects.push(object)
}
Expand Down

0 comments on commit 319c7f8

Please sign in to comment.