diff --git a/package-lock.json b/package-lock.json index b2d95e1..d6e0e41 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@author.io/shell", - "version": "1.5.12", + "version": "1.5.13", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -10,9 +10,9 @@ "integrity": "sha512-TpBNJ0r6YbTwXeLci36GHZLHZx/9gWu9bBFNAinTgEY7H+oTt7OexYKce5UVrYG440Hc60jWZ4pelKCqlgAcIA==" }, "@author.io/table": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/@author.io/table/-/table-1.0.2.tgz", - "integrity": "sha512-LF/qv0/+yZ+qHT+iWtFjVx6Vq4Cm8NaoF3dCjdqhzGT7wtZHViqUb/2zc86mOZTdtZGwcVV6JZt1GgoZXtGCYw==" + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@author.io/table/-/table-1.0.3.tgz", + "integrity": "sha512-JnsndB8kzcyLwYp42teOpdICCP4KZHmzOlFnL/uxfQCxGrQKEIH8Occq8LFQXO7OKri/tOYG5mOhrWxxuoRyzw==" } } } diff --git a/package.json b/package.json index 094d045..a7cba6b 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -53,6 +53,6 @@ }, "dependencies": { "@author.io/arg": "^1.3.3", - "@author.io/table": "^1.0.2" + "@author.io/table": "^1.0.3" } } diff --git a/src/base.js b/src/base.js index 16e091e..45bccbb 100644 --- a/src/base.js +++ b/src/base.js @@ -204,6 +204,8 @@ export default class Base { } } }) + + this.updateHelp() } get name () { @@ -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 () { @@ -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 diff --git a/test/unit/01-sanity/01-sanity.js b/test/unit/01-sanity/01-sanity.js index 7dcc7f6..af0cbb7 100644 --- a/test/unit/01-sanity/01-sanity.js +++ b/test/unit/01-sanity/01-sanity.js @@ -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: '' + } + ] + } + ] + }) + + t.ok(typeof shell.data === 'object', 'Generates a data object representing the shell.') + t.end() +}) diff --git a/test/unit/01-sanity/100-regression.js b/test/unit/01-sanity/100-regression.js new file mode 100644 index 0000000..14f1384 --- /dev/null +++ b/test/unit/01-sanity/100-regression.js @@ -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() +})