Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
fix: added help properties
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Jan 29, 2018
1 parent 3580c5f commit 16908c9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 22 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"tslib": "^1.9.0"
},
"devDependencies": {
"@dxcli/config": "^0.1.32",
"@dxcli/dev": "^2.0.15",
"@dxcli/config": "^0.1.37",
"@dxcli/dev": "^2.0.16",
"@dxcli/dev-semantic-release": "^0.2.0",
"@dxcli/semantic-release": "^0.3.3",
"@dxcli/tslint": "^0.1.3",
Expand Down
41 changes: 34 additions & 7 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,33 @@ export function convertToCached(c: Config.ICommand, opts: ConvertToCachedOptions
hidden: c.hidden,
aliases: c.aliases || [],
help: c.help,
flags: _.mapValues(c.flags, flag => {
if (flag.type === 'boolean') {
return {
type: flag.type,
char: flag.char,
description: flag.description,
hidden: flag.hidden,
name: flag.name,
required: flag.required,
}
}
return {
type: flag.type,
char: flag.char,
description: flag.description,
hidden: flag.hidden,
name: flag.name,
required: flag.required,
}
}),
args: c.args.map(a => ({
name: a.name,
description: a.description,
required: a.required,
// default: a.default && a.default(),
hidden: a.hidden,
})),
load: async () => c,
}
}
Expand Down Expand Up @@ -110,7 +137,7 @@ export default abstract class Command {

protected async init(argv: string[], opts: Config.ICommandOptions) {
this.config = opts.config || await Config.read({root: opts.root || parentModule!})
this.initDebug()
this.initDebug(this.config)
this.debug('init version: %s argv: %o', this.ctor._base, argv)
cli.config.context.command = _.compact([this.ctor.id, ...argv]).join(' ')
try {
Expand All @@ -131,13 +158,13 @@ export default abstract class Command {
}
}

protected initDebug() {
protected initDebug(config: Config.IConfig) {
g['http-call'] = g['http-call'] || {}
g['http-call']!.userAgent = this.config.userAgent
this.debug = require('debug')(`@dxcli/command:${this.ctor.id || this.config.name}`)
cli.config.context.version = this.config.userAgent
if (this.config.debug) cli.config.debug = true
cli.config.errlog = this.config.errlog
g['http-call']!.userAgent = config.userAgent
this.debug = require('debug')(`@dxcli/command:${this.ctor.id || config.name}`)
cli.config.context.version = config.userAgent
if (config.debug) cli.config.debug = true
cli.config.errlog = config.errlog
}

protected async done() {
Expand Down
21 changes: 8 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@
dependencies:
find-up "^2.1.0"

"@dxcli/config@^0.1.32":
version "0.1.32"
resolved "https://registry.yarnpkg.com/@dxcli/config/-/config-0.1.32.tgz#b07b33cc9f91031ff795983bacf8a84f60294ecb"
"@dxcli/config@^0.1.37":
version "0.1.37"
resolved "https://registry.yarnpkg.com/@dxcli/config/-/config-0.1.37.tgz#7014bd6a6d2ae83d40bfe153c06b3a3e1e35dfd2"
dependencies:
cli-ux "^3.3.8"
debug "^3.1.0"
Expand Down Expand Up @@ -139,11 +139,10 @@
semantic-release "^12.2.5"
shelljs "^0.8.1"

"@dxcli/dev@^2.0.15":
version "2.0.15"
resolved "https://registry.yarnpkg.com/@dxcli/dev/-/dev-2.0.15.tgz#2984dabb5e8069515ed328cb59d920a00bee7483"
"@dxcli/dev@^2.0.16":
version "2.0.16"
resolved "https://registry.yarnpkg.com/@dxcli/dev/-/dev-2.0.16.tgz#8d1d30fb02a02a1595d74bf464e71593228b0e93"
dependencies:
"@dxcli/nyc-config" "^0.0.4"
"@types/ansi-styles" "^2.0.30"
"@types/chai" "^4.1.2"
"@types/lodash" "^4.14.97"
Expand All @@ -154,13 +153,9 @@
"@types/read-pkg" "^3.0.0"
"@types/strip-ansi" "^3.0.0"
"@types/supports-color" "^3.1.0"
eslint-config-dxcli "^1.2.0"
eslint-config-dxcli "^1.2.1"
nyc "^11.4.1"

"@dxcli/nyc-config@^0.0.4":
version "0.0.4"
resolved "https://registry.yarnpkg.com/@dxcli/nyc-config/-/nyc-config-0.0.4.tgz#bd60c089aaa6d5da34e415bab6bc527d8c35a210"

"@dxcli/parser@^0.0.5":
version "0.0.5"
resolved "https://registry.yarnpkg.com/@dxcli/parser/-/parser-0.0.5.tgz#51daf8133e8cec6ff21bfa464c4d58cd46b5ed99"
Expand Down Expand Up @@ -1497,7 +1492,7 @@ eslint-ast-utils@^1.0.0:
lodash.get "^4.4.2"
lodash.zip "^4.2.0"

eslint-config-dxcli@^1.2.0:
eslint-config-dxcli@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/eslint-config-dxcli/-/eslint-config-dxcli-1.2.1.tgz#8e65ee698fa77e9485462c788fa466edffccc13d"
dependencies:
Expand Down

0 comments on commit 16908c9

Please sign in to comment.