Skip to content

Commit

Permalink
examples: more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
esatterwhite committed Dec 31, 2017
1 parent fd61ccf commit 4ef03cc
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/cli.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*jshint laxcomma: true, smarttabs: true, node:true, mocha: true*/
const cli = require('../')
const commands = require('./commands')
cli.set({
exitOnError: true
, color: 'green'
, name: 'example'
})

const commands = require('./commands')
for (const [name, command] of Object.entries(commands)) {
cli.use(name, command)
}
Expand Down
7 changes: 5 additions & 2 deletions examples/commands/flip.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const cli = require('../../')

const CHARS = {
// uppercase (incomplete)
'A':'∀',
Expand Down Expand Up @@ -89,7 +88,11 @@ Object.keys(CHARS).forEach(function (key) {
module.exports = new cli.Command({
interactive: false
, description: 'flips text upside-down'
, usage: `${cli.get('name')} flip [word]`
, usage: [
`${cli.get('name')} flip <${cli.colorize('word')}>`
, `${cli.get('name')} flip ${cli.colorize('test')}`
, `${cli.get('name')} flip ${cli.colorize('Hello World!')}`
]
, run: async function(word) {
if (!word) return
var result = ''
Expand Down
1 change: 1 addition & 0 deletions examples/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ module.exports = {
hello: require('./hello')
, foaas: require('./foaas')
, flip: require('./flip')
, ui: require('./ui')
}
88 changes: 88 additions & 0 deletions examples/commands/ui.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
'use strict'

const toArray = require('mout/lang/toArray')
const cli = require('../../')
const spinners = require('cli-spinners')
module.exports = new cli.Command({
description: 'Allows you to play with progress spinners and displays'
, name: 'ui'
, usage: [
`${cli.bold("Usage:")}`
, ` ${cli.get('name')} ui <${cli.colorize('options')}>`
, ` ${cli.get('name')} ui --interactive`
, ` ${cli.get('name')} ui --info=test --warn=foo --fail=bar --delay=2 --spinner=dots5`
]
, flags: {
info: {
type: [String, Array]
, description: 'info messages to display'
, required: false
}
, warn: {
type: [String, Array]
, description: 'warning messages to display'
, required: false
}
, fail: {
type: [String, Array]
, description: 'failure messages to display'
, required: false
}
, succeed: {
type: [String, Array]
, description: 'success messages to display'
, required: false
}
, spinner: {
type: String
, description: 'The spinner type to use'
, required: false
, default: 'dots7'
, choices: Object.keys(spinners)
}
, delay: {
type: Number
, description: 'time delay (sec) between messages'
, default: 1
}
}
, run: async function(cmd, data) {
this.ui.spinner = spinners[data.spinner]
for (const word of toArray(data.info)) {
this.ui.start('info...')
await new Promise((resolve) => {
setTimeout(() => {
this.ui.info(word)
resolve()
}, data.delay * 1000)
})
}
for (const word of toArray(data.warn)) {
this.ui.start('warn...')
await new Promise((resolve) => {
setTimeout(() => {
this.ui.warn(word)
resolve()
}, data.delay * 1000)
})
}
for (const word of toArray(data.fail)) {
this.ui.start('fail...')
await new Promise((resolve) => {
setTimeout(() => {
this.ui.fail(word)
resolve()
}, data.delay * 1000)
})
}
for (const word of toArray(data.succeed)) {
this.ui.start('succeed...')
await new Promise((resolve) => {
setTimeout(() => {
this.ui.succeed(word)
resolve()
}, data.delay * 1000)
})
}
}
})

0 comments on commit 4ef03cc

Please sign in to comment.