diff --git a/package.json b/package.json index 6e2a772..103adde 100644 --- a/package.json +++ b/package.json @@ -5,26 +5,26 @@ "author": "Jeff Dickey @jdxcode", "bugs": "https://github.com/oclif/parser/issues", "dependencies": { - "@heroku/linewrap": "^1.0.0" + "@heroku/linewrap": "^1.0.0", + "chalk": "^2.3.2" }, "devDependencies": { - "@oclif/errors": "^1.0.2", - "@oclif/tslint": "^1.0.2", + "@oclif/errors": "^1.0.3", + "@oclif/tslint": "^1.1.0", "@types/chai": "^4.1.2", "@types/mocha": "^5.0.0", "@types/nock": "^9.1.2", - "@types/node": "^9.6.0", + "@types/node": "^9.6.2", "@types/node-notifier": "^0.0.28", "@types/read-pkg": "^3.0.0", "chai": "^4.1.2", - "chalk": "^2.3.2", "concurrently": "^3.5.1", "eslint": "^4.19.1", - "eslint-config-oclif": "^1.3.8", + "eslint-config-oclif": "^1.4.0", "mocha": "^5.0.5", "ts-node": "^5.0.1", "tslint": "^5.9.1", - "typescript": "^2.7.2" + "typescript": "^2.8.1" }, "engines": { "node": ">=8.0.0" diff --git a/src/deps.ts b/src/deps.ts deleted file mode 100644 index decf230..0000000 --- a/src/deps.ts +++ /dev/null @@ -1,26 +0,0 @@ -import chalk = require('chalk') - -import args = require('./args') -import errors = require('./errors') -import flags = require('./flags') -import list = require('./list') -import parse = require('./parse') -import validate = require('./validate') - -export const deps = { - // local - get args(): typeof args { return args }, - get flags(): typeof flags { return flags }, - get parse(): typeof parse { return parse }, - get validate(): typeof validate { return validate }, - get renderList(): typeof list.renderList { return list.renderList }, - get errors(): typeof errors { return errors }, - - // remote - get chalk(): typeof chalk.default | undefined { - try { - return chalk.default - // tslint:disable-next-line no-unused - } catch (err) {} - }, -} diff --git a/src/errors.ts b/src/errors.ts index 2ecdb27..18156d1 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -1,9 +1,9 @@ import {CLIError} from '@oclif/errors' import {Arg} from './args' -import {deps} from './deps' import * as flags from './flags' import {flagUsages} from './help' +import {renderList} from './list' import {ParserInput, ParserOutput} from './parse' export interface ICLIParseErrorOptions { @@ -30,7 +30,7 @@ export class RequiredArgsError extends CLIParseError { let message = `Missing ${args.length} required arg${args.length === 1 ? '' : 's'}` const namedArgs = args.filter(a => a.name) if (namedArgs.length) { - const list = deps.renderList(namedArgs.map(a => [a.name, a.description] as [string, string])) + const list = renderList(namedArgs.map(a => [a.name, a.description] as [string, string])) message += `:\n${list}` } super({parse, message}) @@ -42,7 +42,7 @@ export class RequiredFlagError extends CLIParseError { public flags: flags.IFlag[] constructor({flags, parse}: ICLIParseErrorOptions & { flags: flags.IFlag[] }) { - const usage = deps.renderList(flagUsages(flags, {displayRequired: false})) + const usage = renderList(flagUsages(flags, {displayRequired: false})) const message = `Missing required flag${flags.length === 1 ? '' : 's'}:\n${usage}` super({parse, message}) this.flags = flags diff --git a/src/help.ts b/src/help.ts index a757d95..f2a8135 100644 --- a/src/help.ts +++ b/src/help.ts @@ -1,9 +1,10 @@ -import {deps} from './deps' +import chalk from 'chalk' + import {IFlag} from './flags' import {sortBy} from './util' function dim(s: string): string { - if (deps.chalk) return deps.chalk.dim(s) + if (chalk) return chalk.dim(s) return s } diff --git a/src/index.ts b/src/index.ts index a7199d0..2e6da58 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,12 +1,12 @@ // tslint:disable interface-over-type-literal import * as args from './args' -import {OutputArgs, OutputFlags, ParserOutput as Output} from './parse' +import {OutputArgs, OutputFlags, Parser, ParserOutput as Output} from './parse' export {args} import * as flags from './flags' +import {validate} from './validate' export {flags} export {flagUsages} from './help' -import {deps} from './deps' export type Input = { flags?: flags.Input @@ -20,17 +20,17 @@ export function parse(argv: stri const input = { argv, context: options.context, - args: (options.args || []).map((a: any) => deps.args.newArg(a as any)), + args: (options.args || []).map((a: any) => args.newArg(a as any)), '--': options['--'], flags: { - color: deps.flags.defaultFlags.color, + color: flags.defaultFlags.color, ...((options.flags || {})) as any, }, strict: options.strict !== false, } - const parser = new deps.parse.Parser(input) + const parser = new Parser(input) const output = parser.parse() - deps.validate.validate({input, output}) + validate({input, output}) return output as any } diff --git a/src/validate.ts b/src/validate.ts index 9203ae5..8719d41 100644 --- a/src/validate.ts +++ b/src/validate.ts @@ -1,4 +1,4 @@ -import {deps} from './deps' +import {RequiredArgsError, RequiredFlagError, UnexpectedArgsError} from './errors' import {ParserInput, ParserOutput} from './parse' export function validate(parse: { input: ParserInput; output: ParserOutput }) { @@ -6,12 +6,12 @@ export function validate(parse: { input: ParserInput; output: ParserOutput maxArgs) { const extras = parse.output.argv.slice(maxArgs) - throw new deps.errors.UnexpectedArgsError({parse, args: extras}) + throw new UnexpectedArgsError({parse, args: extras}) } const requiredArgs = parse.input.args.filter(a => a.required) const missingRequiredArgs = requiredArgs.slice(parse.output.argv.length) if (missingRequiredArgs.length) { - throw new deps.errors.RequiredArgsError({parse, args: missingRequiredArgs}) + throw new RequiredArgsError({parse, args: missingRequiredArgs}) } } @@ -19,7 +19,7 @@ export function validate(parse: { input: ParserInput; output: ParserOutput parse.input.flags[f]) .filter(f => f.required && !parse.output.flags[f.name]) - if (flags.length) throw new deps.errors.RequiredFlagError({parse, flags}) + if (flags.length) throw new RequiredFlagError({parse, flags}) } validateArgs() diff --git a/yarn.lock b/yarn.lock index cad3442..e92cbc5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6,9 +6,9 @@ version "1.0.0" resolved "https://registry.yarnpkg.com/@heroku/linewrap/-/linewrap-1.0.0.tgz#a9d4e99f0a3e423a899b775f5f3d6747a1ff15c6" -"@oclif/errors@^1.0.2": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@oclif/errors/-/errors-1.0.2.tgz#0a3f773d673a3ccd8dc26bf2e3c49580afcbe30e" +"@oclif/errors@^1.0.3": + version "1.0.3" + resolved "https://registry.yarnpkg.com/@oclif/errors/-/errors-1.0.3.tgz#f23c024075855c7d116d041ee158f99bd51175af" dependencies: clean-stack "^1.3.0" fs-extra "^5.0.0" @@ -16,11 +16,11 @@ strip-ansi "^4.0.0" wrap-ansi "^3.0.1" -"@oclif/tslint@^1.0.2": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@oclif/tslint/-/tslint-1.0.2.tgz#793d39758082f359469dba8ce5cfba041d7a7847" +"@oclif/tslint@^1.1.0": + version "1.1.0" + resolved "https://registry.yarnpkg.com/@oclif/tslint/-/tslint-1.1.0.tgz#a2d494a61afa882a685fe5f4d866dafd18990728" dependencies: - tslint-xo "^0.6.0" + tslint-xo "^0.7.0" "@types/chai@^4.1.2": version "4.1.2" @@ -46,9 +46,9 @@ version "9.4.0" resolved "https://registry.yarnpkg.com/@types/node/-/node-9.4.0.tgz#b85a0bcf1e1cc84eb4901b7e96966aedc6f078d1" -"@types/node@^9.6.0": - version "9.6.0" - resolved "https://registry.yarnpkg.com/@types/node/-/node-9.6.0.tgz#d3480ee666df9784b1001a1872a2f6ccefb6c2d7" +"@types/node@^9.6.2": + version "9.6.2" + resolved "https://registry.yarnpkg.com/@types/node/-/node-9.6.2.tgz#e49ac1adb458835e95ca6487bc20f916b37aff23" "@types/normalize-package-data@*": version "2.4.0" @@ -366,7 +366,7 @@ diff@^3.1.0, diff@^3.2.0: version "3.4.0" resolved "https://registry.yarnpkg.com/diff/-/diff-3.4.0.tgz#b1d85507daf3964828de54b37d0d73ba67dda56c" -doctrine@^0.7.2: +doctrine@0.7.2: version "0.7.2" resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-0.7.2.tgz#7cb860359ba3be90e040b26b729ce4bfa654c523" dependencies: @@ -390,34 +390,34 @@ eslint-ast-utils@^1.0.0: lodash.get "^4.4.2" lodash.zip "^4.2.0" -eslint-config-oclif@^1.3.8: - version "1.3.8" - resolved "https://registry.yarnpkg.com/eslint-config-oclif/-/eslint-config-oclif-1.3.8.tgz#901b2b9603b0e7c1b4f028fa48a7fb5098fe2a68" +eslint-config-oclif@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/eslint-config-oclif/-/eslint-config-oclif-1.4.0.tgz#a165329e015bc3841d23bd374d70c2f96dc1078c" dependencies: - eslint-config-xo-space "^0.17.0" - eslint-plugin-mocha "^4.11.0" - eslint-plugin-node "^6.0.0" + eslint-config-xo-space "^0.18.0" + eslint-plugin-mocha "^4.12.1" + eslint-plugin-node "^6.0.1" eslint-plugin-unicorn "^4.0.2" -eslint-config-xo-space@^0.17.0: - version "0.17.0" - resolved "https://registry.yarnpkg.com/eslint-config-xo-space/-/eslint-config-xo-space-0.17.0.tgz#b712feb4f4547e28001900cbeecc9c2f2f456af2" +eslint-config-xo-space@^0.18.0: + version "0.18.0" + resolved "https://registry.yarnpkg.com/eslint-config-xo-space/-/eslint-config-xo-space-0.18.0.tgz#92c8130b1ebaad9162bb822fdc8bc8e9f4fa5b8a" dependencies: - eslint-config-xo "^0.18.0" + eslint-config-xo "^0.20.0" -eslint-config-xo@^0.18.0: - version "0.18.2" - resolved "https://registry.yarnpkg.com/eslint-config-xo/-/eslint-config-xo-0.18.2.tgz#0a157120875619929e735ffd6b185c41e8a187af" +eslint-config-xo@^0.20.0: + version "0.20.1" + resolved "https://registry.yarnpkg.com/eslint-config-xo/-/eslint-config-xo-0.20.1.tgz#ad04db35e62bacedcf7b7e8a76388364a78d616d" -eslint-plugin-mocha@^4.11.0: - version "4.11.0" - resolved "https://registry.yarnpkg.com/eslint-plugin-mocha/-/eslint-plugin-mocha-4.11.0.tgz#91193a2f55e20a5e35974054a0089d30198ee578" +eslint-plugin-mocha@^4.12.1: + version "4.12.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-mocha/-/eslint-plugin-mocha-4.12.1.tgz#dbacc543b178b4536ec5b19d7f8e8864d85404bf" dependencies: - ramda "^0.24.1" + ramda "^0.25.0" -eslint-plugin-node@^6.0.0: - version "6.0.0" - resolved "https://registry.yarnpkg.com/eslint-plugin-node/-/eslint-plugin-node-6.0.0.tgz#5ad5ee6b5346aec6cc9cde0b8619caed2c6d8f25" +eslint-plugin-node@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-node/-/eslint-plugin-node-6.0.1.tgz#bf19642298064379315d7a4b2a75937376fa05e4" dependencies: ignore "^3.3.6" minimatch "^3.0.4" @@ -944,9 +944,9 @@ pseudomap@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3" -ramda@^0.24.1: - version "0.24.1" - resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.24.1.tgz#c3b7755197f35b8dc3502228262c4c91ddb6b857" +ramda@^0.25.0: + version "0.25.0" + resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.25.0.tgz#8fdf68231cffa90bc2f9460390a0cb74a29b29a9" readable-stream@^2.2.2: version "2.3.3" @@ -1179,7 +1179,7 @@ ts-node@^5.0.1: source-map-support "^0.5.3" yn "^2.0.0" -tslib@^1.0.0, tslib@^1.7.1, tslib@^1.8.0, tslib@^1.8.1: +tslib@1.9.0, tslib@^1.7.1, tslib@^1.8.0, tslib@^1.8.1: version "1.9.0" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8" @@ -1190,13 +1190,13 @@ tslint-consistent-codestyle@^1.11.0: tslib "^1.7.1" tsutils "^2.12.2" -tslint-eslint-rules@^4.1.1: - version "4.1.1" - resolved "https://registry.yarnpkg.com/tslint-eslint-rules/-/tslint-eslint-rules-4.1.1.tgz#7c30e7882f26bc276bff91d2384975c69daf88ba" +tslint-eslint-rules@^5.1.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/tslint-eslint-rules/-/tslint-eslint-rules-5.1.0.tgz#3232b318da55dbb5a83e3f5d657c1ddbb27b9ff2" dependencies: - doctrine "^0.7.2" - tslib "^1.0.0" - tsutils "^1.4.0" + doctrine "0.7.2" + tslib "1.9.0" + tsutils "2.8.0" tslint-microsoft-contrib@^5.0.2: version "5.0.2" @@ -1204,12 +1204,12 @@ tslint-microsoft-contrib@^5.0.2: dependencies: tsutils "^2.12.1" -tslint-xo@^0.6.0: - version "0.6.0" - resolved "https://registry.yarnpkg.com/tslint-xo/-/tslint-xo-0.6.0.tgz#95a05b8dcac7aaa1f4d6ca1397a3c4c45a8b848e" +tslint-xo@^0.7.0: + version "0.7.0" + resolved "https://registry.yarnpkg.com/tslint-xo/-/tslint-xo-0.7.0.tgz#be5a1d67f8ade5d92aa8c0a21d9cfdcbaf06f3e0" dependencies: tslint-consistent-codestyle "^1.11.0" - tslint-eslint-rules "^4.1.1" + tslint-eslint-rules "^5.1.0" tslint-microsoft-contrib "^5.0.2" tslint@^5.9.1: @@ -1229,9 +1229,11 @@ tslint@^5.9.1: tslib "^1.8.0" tsutils "^2.12.1" -tsutils@^1.4.0: - version "1.9.1" - resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-1.9.1.tgz#b9f9ab44e55af9681831d5f28d0aeeaf5c750cb0" +tsutils@2.8.0: + version "2.8.0" + resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.8.0.tgz#0160173729b3bf138628dd14a1537e00851d814a" + dependencies: + tslib "^1.7.1" tsutils@^2.12.1, tsutils@^2.12.2: version "2.19.1" @@ -1253,9 +1255,9 @@ typedarray@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" -typescript@^2.7.2: - version "2.7.2" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.2.tgz#2d615a1ef4aee4f574425cdff7026edf81919836" +typescript@^2.8.1: + version "2.8.1" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.8.1.tgz#6160e4f8f195d5ba81d4876f9c0cc1fbc0820624" universalify@^0.1.0: version "0.1.1"