Skip to content

Commit

Permalink
Tweaked default help output to follow consistent spacing patterns. Ad…
Browse files Browse the repository at this point in the history
…ded a global reference (symbol) that can be detected by devtools.
  • Loading branch information
coreybutler committed May 6, 2020
1 parent 6843fa2 commit b607a1e
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
!.*.yml
node_modules
test/output/**/*
test/*.txt
/**/*.old
test/package-lock.json
build/package-lock.json
Expand Down
2 changes: 1 addition & 1 deletion src/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down
3 changes: 3 additions & 0 deletions src/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
3 changes: 3 additions & 0 deletions test/unit/01-sanity/01-sanity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b607a1e

Please sign in to comment.