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

Commit 26265e3

Browse files
committed
fix: added enum flag
1 parent 434118c commit 26265e3

File tree

5 files changed

+87
-40
lines changed

5 files changed

+87
-40
lines changed

package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
"tslib": "^1.9.0"
1212
},
1313
"devDependencies": {
14+
"@anycli/config": "^0.2.1",
15+
"@anycli/tslint": "^0.2.0",
1416
"@commitlint/cli": "^6.0.2",
15-
"@commitlint/config-conventional": "^6.0.2",
16-
"@anycli/config": "^0.1.40",
17-
"@anycli/tslint": "^0.1.3",
17+
"@commitlint/config-conventional": "^6.0.3",
1818
"@types/chai": "^4.1.2",
1919
"@types/lodash": "^4.14.98",
2020
"@types/mocha": "^2.2.47",
@@ -23,9 +23,9 @@
2323
"@types/node-notifier": "^0.0.28",
2424
"@types/read-pkg": "^3.0.0",
2525
"chai": "^4.1.2",
26-
"cli-ux": "^3.3.8",
26+
"cli-ux": "^3.3.9",
2727
"eslint": "^4.16.0",
28-
"eslint-config-anycli": "^1.2.1",
28+
"eslint-config-anycli": "^1.3.0",
2929
"fancy-test": "^0.6.5",
3030
"http-call": "^5.0.2",
3131
"husky": "^0.14.3",
@@ -36,7 +36,7 @@
3636
"nps-utils": "^1.5.0",
3737
"ts-node": "^4.1.0",
3838
"typedoc": "^0.9.0",
39-
"typescript": "^2.6.2"
39+
"typescript": "^2.7.1"
4040
},
4141
"engines": {
4242
"node": ">=8.0.0"

src/command.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,21 @@ export default abstract class Command {
4848
return convertToCached(this, opts)
4949
}
5050

51-
config: Config.IConfig
52-
argv: string[]
53-
flags: flags.Output
54-
args: args.Output
51+
config!: Config.IConfig
52+
argv!: string[]
53+
flags!: flags.Output
54+
args!: args.Output
5555

5656
// prevent setting things that need to be static
57-
topic: null
58-
command: null
59-
description: null
60-
hidden: null
61-
usage: null
62-
help: null
63-
aliases: null
64-
65-
protected debug: (...args: any[]) => void
57+
description!: null
58+
hidden!: null
59+
usage!: null
60+
aliases!: null
61+
title!: null
62+
variableArgs!: null
63+
examples!: null
64+
65+
protected debug!: (...args: any[]) => void
6666

6767
get ctor(): typeof Command {
6868
return this.constructor as typeof Command

src/flags.ts

+15
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@ export function build<T>(defaults: Partial<IOptionFlag<T>>): Definition<T> {
3838
return deps.Parser.flags.build<T>(defaults as any)
3939
}
4040

41+
export function option<T>(options: {parse: IOptionFlag<T>['parse']} & Partial<IOptionFlag<T>>) {
42+
return build<T>({optionType: 'custom', ...options})()
43+
}
44+
45+
const _enum = <T = string>(opts: flags.EnumFlagOptions<T>) => build<T>({
46+
parse(input) {
47+
if (!opts.options.includes(input)) throw new Error(`Expected --${this.name}=${input} to be one of: ${opts.options.join(', ')}`)
48+
return input
49+
},
50+
helpValue: `(${opts.options.join('|')})`,
51+
...opts as any,
52+
optionType: 'enum',
53+
})
54+
export {_enum as enum}
55+
4156
const stringFlag = build({})
4257
export {stringFlag as string}
4358
export {boolean} from '@anycli/parser/lib/flags'

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"declaration": true,
44
"forceConsistentCasingInFileNames": true,
55
"importHelpers": true,
6+
"pretty": true,
67
"module": "commonjs",
78
"noUnusedLocals": true,
89
"noUnusedParameters": true,

yarn.lock

+52-21
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# yarn lockfile v1
33

44

5-
"@anycli/config@^0.1.40":
6-
version "0.1.41"
7-
resolved "https://registry.yarnpkg.com/@anycli/config/-/config-0.1.41.tgz#b18b9a6da0202254a5e52991206419188aa75766"
5+
"@anycli/config@^0.2.1":
6+
version "0.2.1"
7+
resolved "https://registry.yarnpkg.com/@anycli/config/-/config-0.2.1.tgz#d32fe5036cd194c34ca32ee6bc5e1a4b0ca3c86f"
88
dependencies:
99
cli-ux "^3.3.8"
1010
debug "^3.1.0"
@@ -25,12 +25,12 @@
2525
version "0.0.3"
2626
resolved "https://registry.yarnpkg.com/@anycli/screen/-/screen-0.0.3.tgz#f0afd970c3ed725702948a45a874ede1fdd9362e"
2727

28-
"@anycli/tslint@^0.1.3":
29-
version "0.1.4"
30-
resolved "https://registry.yarnpkg.com/@anycli/tslint/-/tslint-0.1.4.tgz#9c8d73e07198633a1afdca69cda4b5b844ab3a72"
28+
"@anycli/tslint@^0.2.0":
29+
version "0.2.0"
30+
resolved "https://registry.yarnpkg.com/@anycli/tslint/-/tslint-0.2.0.tgz#192a612e3664f7a18fe6ed693de94de6d4563882"
3131
dependencies:
3232
tslint "^5.9.1"
33-
tslint-xo "^0.5.0"
33+
tslint-xo "^0.6.0"
3434

3535
"@commitlint/cli@^6.0.2":
3636
version "6.0.2"
@@ -44,9 +44,9 @@
4444
lodash.pick "4.4.0"
4545
meow "3.7.0"
4646

47-
"@commitlint/config-conventional@^6.0.2":
48-
version "6.0.2"
49-
resolved "https://registry.yarnpkg.com/@commitlint/config-conventional/-/config-conventional-6.0.2.tgz#8ef87a6facb75b3377b2760b0e91097f8ec64db4"
47+
"@commitlint/config-conventional@^6.0.3":
48+
version "6.0.3"
49+
resolved "https://registry.yarnpkg.com/@commitlint/config-conventional/-/config-conventional-6.0.3.tgz#561aa85e29a719415602aac25535db0e99dea281"
5050

5151
"@commitlint/core@^6.0.2":
5252
version "6.0.2"
@@ -534,6 +534,26 @@ cli-ux@^3.3.8:
534534
strip-ansi "^4.0.0"
535535
supports-color "^5.1.0"
536536

537+
cli-ux@^3.3.9:
538+
version "3.3.9"
539+
resolved "https://registry.yarnpkg.com/cli-ux/-/cli-ux-3.3.9.tgz#b3d09bb9057d2ef75cfd492d58359dd923c0a16b"
540+
dependencies:
541+
"@anycli/screen" "^0.0.3"
542+
"@heroku/linewrap" "^1.0.0"
543+
ansi-styles "^3.2.0"
544+
cardinal "^1.0.0"
545+
chalk "^2.3.0"
546+
clean-stack "^1.3.0"
547+
extract-stack "^1.0.0"
548+
fs-extra "^5.0.0"
549+
indent-string "^3.2.0"
550+
lodash "^4.17.4"
551+
node-notifier "^5.2.1"
552+
password-prompt "^1.0.4"
553+
semver "^5.5.0"
554+
strip-ansi "^4.0.0"
555+
supports-color "^5.1.0"
556+
537557
cli-width@^2.0.0:
538558
version "2.2.0"
539559
resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-2.2.0.tgz#ff19ede8a9a5e579324147b0c11f0fbcbabed639"
@@ -823,11 +843,12 @@ eslint-ast-utils@^1.0.0:
823843
lodash.get "^4.4.2"
824844
lodash.zip "^4.2.0"
825845

826-
eslint-config-anycli@^1.2.1:
827-
version "1.2.2"
828-
resolved "https://registry.yarnpkg.com/eslint-config-anycli/-/eslint-config-anycli-1.2.2.tgz#8d52cf3594056944918806b6e3003ba3228a800b"
846+
eslint-config-anycli@^1.3.0:
847+
version "1.3.0"
848+
resolved "https://registry.yarnpkg.com/eslint-config-anycli/-/eslint-config-anycli-1.3.0.tgz#35f970a1b382aa5ebe1353b96a6855461b4a1de0"
829849
dependencies:
830850
eslint-config-xo-space "^0.17.0"
851+
eslint-plugin-mocha "^4.11.0"
831852
eslint-plugin-node "^5.2.1"
832853
eslint-plugin-unicorn "^3.0.1"
833854

@@ -841,6 +862,12 @@ eslint-config-xo@^0.18.0:
841862
version "0.18.2"
842863
resolved "https://registry.yarnpkg.com/eslint-config-xo/-/eslint-config-xo-0.18.2.tgz#0a157120875619929e735ffd6b185c41e8a187af"
843864

865+
eslint-plugin-mocha@^4.11.0:
866+
version "4.11.0"
867+
resolved "https://registry.yarnpkg.com/eslint-plugin-mocha/-/eslint-plugin-mocha-4.11.0.tgz#91193a2f55e20a5e35974054a0089d30198ee578"
868+
dependencies:
869+
ramda "^0.24.1"
870+
844871
eslint-plugin-node@^5.2.1:
845872
version "5.2.1"
846873
resolved "https://registry.yarnpkg.com/eslint-plugin-node/-/eslint-plugin-node-5.2.1.tgz#80df3253c4d7901045ec87fa660a284e32bdca29"
@@ -2029,6 +2056,10 @@ qs@^6.5.1:
20292056
version "6.5.1"
20302057
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.1.tgz#349cdf6eef89ec45c12d7d5eb3fc0c870343a6d8"
20312058

2059+
ramda@^0.24.1:
2060+
version "0.24.1"
2061+
resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.24.1.tgz#c3b7755197f35b8dc3502228262c4c91ddb6b857"
2062+
20322063
read-pkg-up@^1.0.1:
20332064
version "1.0.1"
20342065
resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-1.0.1.tgz#9d63c13276c065918d57f002a57f40a1b643fb02"
@@ -2529,19 +2560,19 @@ tslint-eslint-rules@^4.1.1:
25292560
tslib "^1.0.0"
25302561
tsutils "^1.4.0"
25312562

2532-
tslint-microsoft-contrib@^5.0.1:
2563+
tslint-microsoft-contrib@^5.0.2:
25332564
version "5.0.2"
25342565
resolved "https://registry.yarnpkg.com/tslint-microsoft-contrib/-/tslint-microsoft-contrib-5.0.2.tgz#ecc2a797f777a12f0066944cec0c81a9e7c59ee9"
25352566
dependencies:
25362567
tsutils "^2.12.1"
25372568

2538-
tslint-xo@^0.5.0:
2539-
version "0.5.0"
2540-
resolved "https://registry.yarnpkg.com/tslint-xo/-/tslint-xo-0.5.0.tgz#56e591dcd2731de35e7462a0dfa1214731ba9f27"
2569+
tslint-xo@^0.6.0:
2570+
version "0.6.0"
2571+
resolved "https://registry.yarnpkg.com/tslint-xo/-/tslint-xo-0.6.0.tgz#95a05b8dcac7aaa1f4d6ca1397a3c4c45a8b848e"
25412572
dependencies:
25422573
tslint-consistent-codestyle "^1.11.0"
25432574
tslint-eslint-rules "^4.1.1"
2544-
tslint-microsoft-contrib "^5.0.1"
2575+
tslint-microsoft-contrib "^5.0.2"
25452576

25462577
tslint@^5.9.1:
25472578
version "5.9.1"
@@ -2628,9 +2659,9 @@ [email protected]:
26282659
version "2.4.1"
26292660
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.4.1.tgz#c3ccb16ddaa0b2314de031e7e6fee89e5ba346bc"
26302661

2631-
typescript@^2.6.2:
2632-
version "2.6.2"
2633-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.6.2.tgz#3c5b6fd7f6de0914269027f03c0946758f7673a4"
2662+
typescript@^2.7.1:
2663+
version "2.7.1"
2664+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.1.tgz#bb3682c2c791ac90e7c6210b26478a8da085c359"
26342665

26352666
uglify-js@^2.6:
26362667
version "2.8.29"

0 commit comments

Comments
 (0)