Skip to content

Commit

Permalink
Updated dependencies (fixed a regression in the table lib)
Browse files Browse the repository at this point in the history
  • Loading branch information
coreybutler committed May 9, 2020
1 parent ea354cc commit b51e3d4
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 12 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@author.io/shell",
"version": "1.5.12",
"version": "1.5.13",
"description": "A micro-framework for creating CLI-like experiences. This supports Node.js and browsers.",
"main": "src/index.js",
"scripts": {
Expand Down Expand Up @@ -53,6 +53,6 @@
},
"dependencies": {
"@author.io/arg": "^1.3.3",
"@author.io/table": "^1.0.2"
"@author.io/table": "^1.0.3"
}
}
14 changes: 8 additions & 6 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ export default class Base {
}
}
})

this.updateHelp()
}

get name () {
Expand Down Expand Up @@ -270,17 +272,17 @@ export default class Base {
return typeof this.#customUsage === 'function' ? this.#customUsage() : this.#customUsage
}

this.updateHelp()

return this.#formattedDefaultHelp.usage
}

set usage (value) {
if (typeof value === 'string' && value.trim().length === 0) {
this.#customUsage = null
value = null
}

this.#customUsage = value

this.updateHelp()
}

get help () {
Expand All @@ -292,17 +294,17 @@ export default class Base {
return ''
}

this.updateHelp()

return this.#formattedDefaultHelp.help
}

set help (value) {
if (typeof value === 'string' && value.trim().length === 0) {
this.#customHelp = null
value = null
}

this.#customHelp = value

this.updateHelp()
}

// @private
Expand Down
25 changes: 25 additions & 0 deletions test/unit/01-sanity/01-sanity.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,28 @@ test('Default command help (regression test)', t => {
t.pass('Ran without error.')
t.end()
})

test('Basic Introspection', t => {
const shell = new Shell({
name: 'test',
version: '1.0.0',
disableHelp: true,
commands: [
{
name: 'account',
description: 'Perform operations on a user account.',
handler: (meta, cb) => { },
commands: [
{
name: 'create',
description: 'Create a user account.',
arguments: '<email>'
}
]
}
]
})

t.ok(typeof shell.data === 'object', 'Generates a data object representing the shell.')
t.end()
})
27 changes: 27 additions & 0 deletions test/unit/01-sanity/100-regression.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'source-map-support/register.js'
import test from 'tape'
import { Shell } from '../../.node/index.js'

// The range error was caused by the underlying table library.
// When a default help message was generated, a negative column
// width (representing "infinite" width) was not being converted
// to the width of the content, causing a method to execute infinitely.
test('Extending shell creates RangeError for data attribute', t => {
class CLIClient extends Shell {
exec (input, cb) {
console.log(input)
super.exec(...arguments)
}
}

const sh = new CLIClient({
name: 'test',
commands: [{
name: 'cmd',
handler () {}
}]
})

t.ok(sh.data.name === 'test', 'Extended shell still provides underlying data.')
t.end()
})

0 comments on commit b51e3d4

Please sign in to comment.