diff --git a/.gitignore b/.gitignore index 178c500..2190ef9 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ !.*.yml node_modules test/output/**/* +test/*.txt /**/*.old test/package-lock.json build/package-lock.json diff --git a/src/command.js b/src/command.js index 37a51fb..59eba05 100644 --- a/src/command.js +++ b/src/command.js @@ -45,7 +45,7 @@ export default class Command extends Base { this.#pattern = cfg.pattern || /[\s\S]+/i if (cfg.alias && !cfg.aliases) { - cfg.aliases = Array.isArray(cfg.alias) ? cfg.alias : [cfg.alias] + cfg.aliases = typeof cfg.alias === 'string' ? [cfg.alias] : (Array.isArray(cfg.alias) ? cfg.alias : Array.from(cfg.alias)) delete cfg.alias } diff --git a/src/format.js b/src/format.js index 03c8533..0b8e1ca 100644 --- a/src/format.js +++ b/src/format.js @@ -106,7 +106,7 @@ class Formatter { if (subcommands.trim().length === 0) { subcommands = '' } - return usage + (flags.size > 0 ? '\n\nFlags:' + table.output : '') + subcommands + return usage + (flags.size > 0 ? '\n\nFlags:\n' + table.output : '') + subcommands } else if (this.#data instanceof Shell) { return [usage, this.subcommands].join('\n') } diff --git a/src/shell.js b/src/shell.js index 999a718..0c584b3 100644 --- a/src/shell.js +++ b/src/shell.js @@ -38,6 +38,9 @@ export default class Shell extends Base { this.#version = cfg.version || '1.0.0' this.#maxHistoryItems = cfg.maxhistory || cfg.maxHistoryItems || 100 this.#tabWidth = cfg.hasOwnProperty('tabWidth') ? cfg.tabWidth : 4 + + // This sets a global symbol that dev tools can find. + Object.defineProperty(globalThis, Symbol('SHELL_INTEGRATIONS'), { enumerable: false, get () { return this }}) } get data () { diff --git a/test/unit/01-sanity/01-sanity.js b/test/unit/01-sanity/01-sanity.js index ad61253..d6c61eb 100644 --- a/test/unit/01-sanity/01-sanity.js +++ b/test/unit/01-sanity/01-sanity.js @@ -2,6 +2,7 @@ import 'source-map-support/register.js' import test from 'tape' import { Command, Shell, Formatter } from '../../.node/index.js' // import fs from 'fs' +// import path from 'path' test('Sanity Check - Shell', t => { const shell = new Shell({ @@ -80,9 +81,11 @@ test('Output Formatting', t => { t.ok(formatter instanceof Formatter, 'Basic formatter instantiates correctly.') // fs.writeFileSync('./test.txt', Buffer.from(formatter.help)) + // console.log(formatter.help) t.ok(formatter.help === `test cmd|c [FLAGS] Flags: + -test [-t] test description -more [-m, -mr] This is a longer description that should break onto more than one line, or perhaps even more than one