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

Commit 9c5fb0f

Browse files
committed
fix: clean up requires
1 parent 3eac9b4 commit 9c5fb0f

File tree

7 files changed

+76
-99
lines changed

7 files changed

+76
-99
lines changed

package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@
55
"author": "Jeff Dickey @jdxcode",
66
"bugs": "https://github.com/oclif/parser/issues",
77
"dependencies": {
8-
"@heroku/linewrap": "^1.0.0"
8+
"@heroku/linewrap": "^1.0.0",
9+
"chalk": "^2.3.2"
910
},
1011
"devDependencies": {
11-
"@oclif/errors": "^1.0.2",
12-
"@oclif/tslint": "^1.0.2",
12+
"@oclif/errors": "^1.0.3",
13+
"@oclif/tslint": "^1.1.0",
1314
"@types/chai": "^4.1.2",
1415
"@types/mocha": "^5.0.0",
1516
"@types/nock": "^9.1.2",
16-
"@types/node": "^9.6.0",
17+
"@types/node": "^9.6.2",
1718
"@types/node-notifier": "^0.0.28",
1819
"@types/read-pkg": "^3.0.0",
1920
"chai": "^4.1.2",
20-
"chalk": "^2.3.2",
2121
"concurrently": "^3.5.1",
2222
"eslint": "^4.19.1",
23-
"eslint-config-oclif": "^1.3.8",
23+
"eslint-config-oclif": "^1.4.0",
2424
"mocha": "^5.0.5",
2525
"ts-node": "^5.0.1",
2626
"tslint": "^5.9.1",
27-
"typescript": "^2.7.2"
27+
"typescript": "^2.8.1"
2828
},
2929
"engines": {
3030
"node": ">=8.0.0"

src/deps.ts

-26
This file was deleted.

src/errors.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {CLIError} from '@oclif/errors'
22

33
import {Arg} from './args'
4-
import {deps} from './deps'
54
import * as flags from './flags'
65
import {flagUsages} from './help'
6+
import {renderList} from './list'
77
import {ParserInput, ParserOutput} from './parse'
88

99
export interface ICLIParseErrorOptions {
@@ -30,7 +30,7 @@ export class RequiredArgsError extends CLIParseError {
3030
let message = `Missing ${args.length} required arg${args.length === 1 ? '' : 's'}`
3131
const namedArgs = args.filter(a => a.name)
3232
if (namedArgs.length) {
33-
const list = deps.renderList(namedArgs.map(a => [a.name, a.description] as [string, string]))
33+
const list = renderList(namedArgs.map(a => [a.name, a.description] as [string, string]))
3434
message += `:\n${list}`
3535
}
3636
super({parse, message})
@@ -42,7 +42,7 @@ export class RequiredFlagError extends CLIParseError {
4242
public flags: flags.IFlag<any>[]
4343

4444
constructor({flags, parse}: ICLIParseErrorOptions & { flags: flags.IFlag<any>[] }) {
45-
const usage = deps.renderList(flagUsages(flags, {displayRequired: false}))
45+
const usage = renderList(flagUsages(flags, {displayRequired: false}))
4646
const message = `Missing required flag${flags.length === 1 ? '' : 's'}:\n${usage}`
4747
super({parse, message})
4848
this.flags = flags

src/help.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import {deps} from './deps'
1+
import chalk from 'chalk'
2+
23
import {IFlag} from './flags'
34
import {sortBy} from './util'
45

56
function dim(s: string): string {
6-
if (deps.chalk) return deps.chalk.dim(s)
7+
if (chalk) return chalk.dim(s)
78
return s
89
}
910

src/index.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// tslint:disable interface-over-type-literal
22

33
import * as args from './args'
4-
import {OutputArgs, OutputFlags, ParserOutput as Output} from './parse'
4+
import {OutputArgs, OutputFlags, Parser, ParserOutput as Output} from './parse'
55
export {args}
66
import * as flags from './flags'
7+
import {validate} from './validate'
78
export {flags}
89
export {flagUsages} from './help'
9-
import {deps} from './deps'
1010

1111
export type Input<TFlags extends flags.Output> = {
1212
flags?: flags.Input<TFlags>
@@ -20,17 +20,17 @@ export function parse<TFlags, TArgs extends {[name: string]: string}>(argv: stri
2020
const input = {
2121
argv,
2222
context: options.context,
23-
args: (options.args || []).map((a: any) => deps.args.newArg(a as any)),
23+
args: (options.args || []).map((a: any) => args.newArg(a as any)),
2424
'--': options['--'],
2525
flags: {
26-
color: deps.flags.defaultFlags.color,
26+
color: flags.defaultFlags.color,
2727
...((options.flags || {})) as any,
2828
},
2929
strict: options.strict !== false,
3030
}
31-
const parser = new deps.parse.Parser(input)
31+
const parser = new Parser(input)
3232
const output = parser.parse()
33-
deps.validate.validate({input, output})
33+
validate({input, output})
3434
return output as any
3535
}
3636

src/validate.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
import {deps} from './deps'
1+
import {RequiredArgsError, RequiredFlagError, UnexpectedArgsError} from './errors'
22
import {ParserInput, ParserOutput} from './parse'
33

44
export function validate(parse: { input: ParserInput; output: ParserOutput<any, any> }) {
55
function validateArgs() {
66
const maxArgs = parse.input.args.length
77
if (parse.input.strict && parse.output.argv.length > maxArgs) {
88
const extras = parse.output.argv.slice(maxArgs)
9-
throw new deps.errors.UnexpectedArgsError({parse, args: extras})
9+
throw new UnexpectedArgsError({parse, args: extras})
1010
}
1111
const requiredArgs = parse.input.args.filter(a => a.required)
1212
const missingRequiredArgs = requiredArgs.slice(parse.output.argv.length)
1313
if (missingRequiredArgs.length) {
14-
throw new deps.errors.RequiredArgsError({parse, args: missingRequiredArgs})
14+
throw new RequiredArgsError({parse, args: missingRequiredArgs})
1515
}
1616
}
1717

1818
function validateFlags() {
1919
const flags = Object.keys(parse.input.flags)
2020
.map(f => parse.input.flags[f])
2121
.filter(f => f.required && !parse.output.flags[f.name])
22-
if (flags.length) throw new deps.errors.RequiredFlagError({parse, flags})
22+
if (flags.length) throw new RequiredFlagError({parse, flags})
2323
}
2424

2525
validateArgs()

yarn.lock

+53-51
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66
version "1.0.0"
77
resolved "https://registry.yarnpkg.com/@heroku/linewrap/-/linewrap-1.0.0.tgz#a9d4e99f0a3e423a899b775f5f3d6747a1ff15c6"
88

9-
"@oclif/errors@^1.0.2":
10-
version "1.0.2"
11-
resolved "https://registry.yarnpkg.com/@oclif/errors/-/errors-1.0.2.tgz#0a3f773d673a3ccd8dc26bf2e3c49580afcbe30e"
9+
"@oclif/errors@^1.0.3":
10+
version "1.0.3"
11+
resolved "https://registry.yarnpkg.com/@oclif/errors/-/errors-1.0.3.tgz#f23c024075855c7d116d041ee158f99bd51175af"
1212
dependencies:
1313
clean-stack "^1.3.0"
1414
fs-extra "^5.0.0"
1515
indent-string "^3.2.0"
1616
strip-ansi "^4.0.0"
1717
wrap-ansi "^3.0.1"
1818

19-
"@oclif/tslint@^1.0.2":
20-
version "1.0.2"
21-
resolved "https://registry.yarnpkg.com/@oclif/tslint/-/tslint-1.0.2.tgz#793d39758082f359469dba8ce5cfba041d7a7847"
19+
"@oclif/tslint@^1.1.0":
20+
version "1.1.0"
21+
resolved "https://registry.yarnpkg.com/@oclif/tslint/-/tslint-1.1.0.tgz#a2d494a61afa882a685fe5f4d866dafd18990728"
2222
dependencies:
23-
tslint-xo "^0.6.0"
23+
tslint-xo "^0.7.0"
2424

2525
"@types/chai@^4.1.2":
2626
version "4.1.2"
@@ -46,9 +46,9 @@
4646
version "9.4.0"
4747
resolved "https://registry.yarnpkg.com/@types/node/-/node-9.4.0.tgz#b85a0bcf1e1cc84eb4901b7e96966aedc6f078d1"
4848

49-
"@types/node@^9.6.0":
50-
version "9.6.0"
51-
resolved "https://registry.yarnpkg.com/@types/node/-/node-9.6.0.tgz#d3480ee666df9784b1001a1872a2f6ccefb6c2d7"
49+
"@types/node@^9.6.2":
50+
version "9.6.2"
51+
resolved "https://registry.yarnpkg.com/@types/node/-/node-9.6.2.tgz#e49ac1adb458835e95ca6487bc20f916b37aff23"
5252

5353
"@types/normalize-package-data@*":
5454
version "2.4.0"
@@ -366,7 +366,7 @@ diff@^3.1.0, diff@^3.2.0:
366366
version "3.4.0"
367367
resolved "https://registry.yarnpkg.com/diff/-/diff-3.4.0.tgz#b1d85507daf3964828de54b37d0d73ba67dda56c"
368368

369-
doctrine@^0.7.2:
369+
370370
version "0.7.2"
371371
resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-0.7.2.tgz#7cb860359ba3be90e040b26b729ce4bfa654c523"
372372
dependencies:
@@ -390,34 +390,34 @@ eslint-ast-utils@^1.0.0:
390390
lodash.get "^4.4.2"
391391
lodash.zip "^4.2.0"
392392

393-
eslint-config-oclif@^1.3.8:
394-
version "1.3.8"
395-
resolved "https://registry.yarnpkg.com/eslint-config-oclif/-/eslint-config-oclif-1.3.8.tgz#901b2b9603b0e7c1b4f028fa48a7fb5098fe2a68"
393+
eslint-config-oclif@^1.4.0:
394+
version "1.4.0"
395+
resolved "https://registry.yarnpkg.com/eslint-config-oclif/-/eslint-config-oclif-1.4.0.tgz#a165329e015bc3841d23bd374d70c2f96dc1078c"
396396
dependencies:
397-
eslint-config-xo-space "^0.17.0"
398-
eslint-plugin-mocha "^4.11.0"
399-
eslint-plugin-node "^6.0.0"
397+
eslint-config-xo-space "^0.18.0"
398+
eslint-plugin-mocha "^4.12.1"
399+
eslint-plugin-node "^6.0.1"
400400
eslint-plugin-unicorn "^4.0.2"
401401

402-
eslint-config-xo-space@^0.17.0:
403-
version "0.17.0"
404-
resolved "https://registry.yarnpkg.com/eslint-config-xo-space/-/eslint-config-xo-space-0.17.0.tgz#b712feb4f4547e28001900cbeecc9c2f2f456af2"
402+
eslint-config-xo-space@^0.18.0:
403+
version "0.18.0"
404+
resolved "https://registry.yarnpkg.com/eslint-config-xo-space/-/eslint-config-xo-space-0.18.0.tgz#92c8130b1ebaad9162bb822fdc8bc8e9f4fa5b8a"
405405
dependencies:
406-
eslint-config-xo "^0.18.0"
406+
eslint-config-xo "^0.20.0"
407407

408-
eslint-config-xo@^0.18.0:
409-
version "0.18.2"
410-
resolved "https://registry.yarnpkg.com/eslint-config-xo/-/eslint-config-xo-0.18.2.tgz#0a157120875619929e735ffd6b185c41e8a187af"
408+
eslint-config-xo@^0.20.0:
409+
version "0.20.1"
410+
resolved "https://registry.yarnpkg.com/eslint-config-xo/-/eslint-config-xo-0.20.1.tgz#ad04db35e62bacedcf7b7e8a76388364a78d616d"
411411

412-
eslint-plugin-mocha@^4.11.0:
413-
version "4.11.0"
414-
resolved "https://registry.yarnpkg.com/eslint-plugin-mocha/-/eslint-plugin-mocha-4.11.0.tgz#91193a2f55e20a5e35974054a0089d30198ee578"
412+
eslint-plugin-mocha@^4.12.1:
413+
version "4.12.1"
414+
resolved "https://registry.yarnpkg.com/eslint-plugin-mocha/-/eslint-plugin-mocha-4.12.1.tgz#dbacc543b178b4536ec5b19d7f8e8864d85404bf"
415415
dependencies:
416-
ramda "^0.24.1"
416+
ramda "^0.25.0"
417417

418-
eslint-plugin-node@^6.0.0:
419-
version "6.0.0"
420-
resolved "https://registry.yarnpkg.com/eslint-plugin-node/-/eslint-plugin-node-6.0.0.tgz#5ad5ee6b5346aec6cc9cde0b8619caed2c6d8f25"
418+
eslint-plugin-node@^6.0.1:
419+
version "6.0.1"
420+
resolved "https://registry.yarnpkg.com/eslint-plugin-node/-/eslint-plugin-node-6.0.1.tgz#bf19642298064379315d7a4b2a75937376fa05e4"
421421
dependencies:
422422
ignore "^3.3.6"
423423
minimatch "^3.0.4"
@@ -944,9 +944,9 @@ pseudomap@^1.0.2:
944944
version "1.0.2"
945945
resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"
946946

947-
ramda@^0.24.1:
948-
version "0.24.1"
949-
resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.24.1.tgz#c3b7755197f35b8dc3502228262c4c91ddb6b857"
947+
ramda@^0.25.0:
948+
version "0.25.0"
949+
resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.25.0.tgz#8fdf68231cffa90bc2f9460390a0cb74a29b29a9"
950950

951951
readable-stream@^2.2.2:
952952
version "2.3.3"
@@ -1179,7 +1179,7 @@ ts-node@^5.0.1:
11791179
source-map-support "^0.5.3"
11801180
yn "^2.0.0"
11811181

1182-
tslib@^1.0.0, tslib@^1.7.1, tslib@^1.8.0, tslib@^1.8.1:
1182+
tslib@1.9.0, tslib@^1.7.1, tslib@^1.8.0, tslib@^1.8.1:
11831183
version "1.9.0"
11841184
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8"
11851185

@@ -1190,26 +1190,26 @@ tslint-consistent-codestyle@^1.11.0:
11901190
tslib "^1.7.1"
11911191
tsutils "^2.12.2"
11921192

1193-
tslint-eslint-rules@^4.1.1:
1194-
version "4.1.1"
1195-
resolved "https://registry.yarnpkg.com/tslint-eslint-rules/-/tslint-eslint-rules-4.1.1.tgz#7c30e7882f26bc276bff91d2384975c69daf88ba"
1193+
tslint-eslint-rules@^5.1.0:
1194+
version "5.1.0"
1195+
resolved "https://registry.yarnpkg.com/tslint-eslint-rules/-/tslint-eslint-rules-5.1.0.tgz#3232b318da55dbb5a83e3f5d657c1ddbb27b9ff2"
11961196
dependencies:
1197-
doctrine "^0.7.2"
1198-
tslib "^1.0.0"
1199-
tsutils "^1.4.0"
1197+
doctrine "0.7.2"
1198+
tslib "1.9.0"
1199+
tsutils "2.8.0"
12001200

12011201
tslint-microsoft-contrib@^5.0.2:
12021202
version "5.0.2"
12031203
resolved "https://registry.yarnpkg.com/tslint-microsoft-contrib/-/tslint-microsoft-contrib-5.0.2.tgz#ecc2a797f777a12f0066944cec0c81a9e7c59ee9"
12041204
dependencies:
12051205
tsutils "^2.12.1"
12061206

1207-
tslint-xo@^0.6.0:
1208-
version "0.6.0"
1209-
resolved "https://registry.yarnpkg.com/tslint-xo/-/tslint-xo-0.6.0.tgz#95a05b8dcac7aaa1f4d6ca1397a3c4c45a8b848e"
1207+
tslint-xo@^0.7.0:
1208+
version "0.7.0"
1209+
resolved "https://registry.yarnpkg.com/tslint-xo/-/tslint-xo-0.7.0.tgz#be5a1d67f8ade5d92aa8c0a21d9cfdcbaf06f3e0"
12101210
dependencies:
12111211
tslint-consistent-codestyle "^1.11.0"
1212-
tslint-eslint-rules "^4.1.1"
1212+
tslint-eslint-rules "^5.1.0"
12131213
tslint-microsoft-contrib "^5.0.2"
12141214

12151215
tslint@^5.9.1:
@@ -1229,9 +1229,11 @@ tslint@^5.9.1:
12291229
tslib "^1.8.0"
12301230
tsutils "^2.12.1"
12311231

1232-
tsutils@^1.4.0:
1233-
version "1.9.1"
1234-
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-1.9.1.tgz#b9f9ab44e55af9681831d5f28d0aeeaf5c750cb0"
1232+
1233+
version "2.8.0"
1234+
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.8.0.tgz#0160173729b3bf138628dd14a1537e00851d814a"
1235+
dependencies:
1236+
tslib "^1.7.1"
12351237

12361238
tsutils@^2.12.1, tsutils@^2.12.2:
12371239
version "2.19.1"
@@ -1253,9 +1255,9 @@ typedarray@^0.0.6:
12531255
version "0.0.6"
12541256
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
12551257

1256-
typescript@^2.7.2:
1257-
version "2.7.2"
1258-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.2.tgz#2d615a1ef4aee4f574425cdff7026edf81919836"
1258+
typescript@^2.8.1:
1259+
version "2.8.1"
1260+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.8.1.tgz#6160e4f8f195d5ba81d4876f9c0cc1fbc0820624"
12591261

12601262
universalify@^0.1.0:
12611263
version "0.1.1"

0 commit comments

Comments
 (0)