@@ -6,12 +6,20 @@ import { OptionType } from "../lib/common/enums";
66
77interface ITestSetup {
88 injector : Yok ;
9- validatedWith : { called : boolean ; allowUnknown ?: boolean } ;
9+ validatedWith : {
10+ called : boolean ;
11+ allowUnknown ?: boolean ;
12+ isCommandLine ?: boolean ;
13+ } ;
1014}
1115
1216function createTestInjector ( command : ICommand ) : ITestSetup {
1317 const injector = new Yok ( ) ;
14- const validatedWith : { called : boolean ; allowUnknown ?: boolean } = {
18+ const validatedWith : {
19+ called : boolean ;
20+ allowUnknown ?: boolean ;
21+ isCommandLine ?: boolean ;
22+ } = {
1523 called : false ,
1624 } ;
1725
@@ -26,9 +34,14 @@ function createTestInjector(command: ICommand): ITestSetup {
2634 injector . register ( "hooksService" , { } ) ;
2735 injector . register ( "logger" , { warn : ( ) : void => undefined } ) ;
2836 injector . register ( "options" , {
29- validateOptions : ( dashedOptions : any , allowUnknown ?: boolean ) : void => {
37+ validateOptions : (
38+ dashedOptions : any ,
39+ allowUnknown ?: boolean ,
40+ isCommandLine ?: boolean ,
41+ ) : void => {
3042 validatedWith . called = true ;
3143 validatedWith . allowUnknown = allowUnknown ;
44+ validatedWith . isCommandLine = isCommandLine ;
3245 } ,
3346 } ) ;
3447 injector . register ( "staticConfig" , { } ) ;
@@ -43,6 +56,7 @@ function createTestInjector(command: ICommand): ITestSetup {
4356/** What an in-process dispatch touched, recorded off the collaborators. */
4457interface IDispatchRecord {
4558 primedWith : { dashedOptions : any ; allowUnknown ?: boolean } [ ] ;
59+ commandLineParses : number ;
4660 hooks : string [ ] ;
4761 analytics : string [ ] ;
4862 executed : string [ ] [ ] ;
@@ -62,6 +76,7 @@ function createDispatchInjector(command: ICommand): {
6276 const injector = new Yok ( ) ;
6377 const record : IDispatchRecord = {
6478 primedWith : [ ] ,
79+ commandLineParses : 0 ,
6580 hooks : [ ] ,
6681 analytics : [ ] ,
6782 executed : [ ] ,
@@ -74,7 +89,12 @@ function createDispatchInjector(command: ICommand): {
7489 const options : any = {
7590 options : { watch : cliOption } ,
7691 argv : initialArgv ,
77- validateOptions ( dashedOptions : any , allowUnknown ?: boolean ) : void {
92+ validateOptions (
93+ dashedOptions : any ,
94+ allowUnknown ?: boolean ,
95+ isCommandLine ?: boolean ,
96+ ) : void {
97+ record . commandLineParses += isCommandLine ? 1 : 0 ;
7898 record . primedWith . push ( { dashedOptions, allowUnknown } ) ;
7999 // The real parser merges the command's declarations into the shared
80100 // table and re-parses, replacing both.
@@ -173,6 +193,7 @@ describe("commands-service", () => {
173193 await ( < any > service ) . tryExecuteCommandAction ( "info" , [ ] ) ;
174194
175195 assert . isTrue ( validatedWith . called ) ;
196+ assert . isTrue ( validatedWith . isCommandLine ) ;
176197 } ) ;
177198
178199 it ( "tolerates unknown options for a command that forwards them" , async ( ) => {
@@ -200,6 +221,7 @@ describe("commands-service", () => {
200221
201222 await service . runCommand ( "open|ios" ) ;
202223
224+ assert . equal ( record . commandLineParses , 0 ) ;
203225 assert . deepEqual ( record . primedWith , [
204226 { dashedOptions : command . dashedOptions , allowUnknown : true } ,
205227 ] ) ;
0 commit comments