@@ -110,6 +110,23 @@ class NonJsonCommand extends SfCommand<void> {
110
110
}
111
111
}
112
112
113
+ class SuggestionCommand extends SfCommand < void > {
114
+ public static enableJsonFlag = false ;
115
+ public static readonly flags = {
116
+ first : Flags . string ( {
117
+ default : 'My first flag' ,
118
+ required : true ,
119
+ } ) ,
120
+ second : Flags . string ( {
121
+ default : 'My second' ,
122
+ required : true ,
123
+ } ) ,
124
+ } ;
125
+ public async run ( ) : Promise < void > {
126
+ await this . parse ( SuggestionCommand ) ;
127
+ }
128
+ }
129
+
113
130
describe ( 'jsonEnabled' , ( ) => {
114
131
afterEach ( ( ) => {
115
132
delete process . env . SF_CONTENT_TYPE ;
@@ -375,6 +392,69 @@ describe('error standardization', () => {
375
392
}
376
393
} ) ;
377
394
395
+ it ( 'should log correct suggestion when user doesnt wrap with quotes' , async ( ) => {
396
+ const logToStderrStub = $$ . SANDBOX . stub ( SfCommand . prototype , 'logToStderr' ) ;
397
+ try {
398
+ await SuggestionCommand . run ( [ '--first' , 'my' , 'alias' , 'with' , 'spaces' , '--second' , 'my second' , 'value' ] ) ;
399
+ expect ( false , 'error should have been thrown' ) . to . be . true ;
400
+ } catch ( e : unknown ) {
401
+ expect ( e ) . to . be . instanceOf ( SfCommandError ) ;
402
+ const err = e as SfCommand . Error ;
403
+
404
+ // Ensure the error was logged to the console
405
+ expect ( logToStderrStub . callCount ) . to . equal ( 1 ) ;
406
+ expect ( logToStderrStub . firstCall . firstArg ) . to . contain ( err . message ) ;
407
+
408
+ // Ensure the error has expected properties
409
+ expect ( err ) . to . have . property ( 'actions' ) ;
410
+ expect ( err . actions ) . to . deep . equal ( [ '--first "my alias with spaces"' , '--second "my second value"' ] ) ;
411
+ expect ( err ) . to . have . property ( 'exitCode' , 2 ) ;
412
+ expect ( err ) . to . have . property ( 'context' , 'SuggestionCommand' ) ;
413
+ expect ( err ) . to . have . property ( 'data' , undefined ) ;
414
+ expect ( err ) . to . have . property ( 'cause' ) ;
415
+ expect ( err ) . to . have . property ( 'code' , '2' ) ;
416
+ expect ( err ) . to . have . property ( 'status' , 2 ) ;
417
+ expect ( err ) . to . have . property ( 'stack' ) . and . be . ok ;
418
+ expect ( err ) . to . have . property ( 'skipOclifErrorHandling' , true ) ;
419
+ expect ( err ) . to . have . deep . property ( 'oclif' , { exit : 2 } ) ;
420
+
421
+ // Ensure a sfCommandError event was emitted with the expected data
422
+ expect ( sfCommandErrorData [ 0 ] ) . to . equal ( err ) ;
423
+ expect ( sfCommandErrorData [ 1 ] ) . to . equal ( 'suggestioncommand' ) ;
424
+ }
425
+ } ) ;
426
+ it ( 'should log correct suggestion when user doesnt wrap with quotes without flag order' , async ( ) => {
427
+ const logToStderrStub = $$ . SANDBOX . stub ( SfCommand . prototype , 'logToStderr' ) ;
428
+ try {
429
+ await SuggestionCommand . run ( [ '--second' , 'my second value' , '--first' , 'my' , 'alias' , 'with' , 'spaces' ] ) ;
430
+ expect ( false , 'error should have been thrown' ) . to . be . true ;
431
+ } catch ( e : unknown ) {
432
+ expect ( e ) . to . be . instanceOf ( SfCommandError ) ;
433
+ const err = e as SfCommand . Error ;
434
+
435
+ // Ensure the error was logged to the console
436
+ expect ( logToStderrStub . callCount ) . to . equal ( 1 ) ;
437
+ expect ( logToStderrStub . firstCall . firstArg ) . to . contain ( err . message ) ;
438
+
439
+ // Ensure the error has expected properties
440
+ expect ( err ) . to . have . property ( 'actions' ) ;
441
+ expect ( err . actions ) . to . deep . equal ( [ '--first "my alias with spaces"' ] ) ;
442
+ expect ( err ) . to . have . property ( 'exitCode' , 2 ) ;
443
+ expect ( err ) . to . have . property ( 'context' , 'SuggestionCommand' ) ;
444
+ expect ( err ) . to . have . property ( 'data' , undefined ) ;
445
+ expect ( err ) . to . have . property ( 'cause' ) ;
446
+ expect ( err ) . to . have . property ( 'code' , '2' ) ;
447
+ expect ( err ) . to . have . property ( 'status' , 2 ) ;
448
+ expect ( err ) . to . have . property ( 'stack' ) . and . be . ok ;
449
+ expect ( err ) . to . have . property ( 'skipOclifErrorHandling' , true ) ;
450
+ expect ( err ) . to . have . deep . property ( 'oclif' , { exit : 2 } ) ;
451
+
452
+ // Ensure a sfCommandError event was emitted with the expected data
453
+ expect ( sfCommandErrorData [ 0 ] ) . to . equal ( err ) ;
454
+ expect ( sfCommandErrorData [ 1 ] ) . to . equal ( 'suggestioncommand' ) ;
455
+ }
456
+ } ) ;
457
+
378
458
it ( 'should log correct error when command throws an SfError --json' , async ( ) => {
379
459
const logJsonStub = $$ . SANDBOX . stub ( SfCommand . prototype , 'logJson' ) ;
380
460
try {
0 commit comments