@@ -41,39 +41,42 @@ internal void Register(CommandLineApplication app)
4141 remainingArgs = c . Argument ( "" , RemainingArgumentsHelpText , multipleValues : ( RemainingArgumentsCount ?? 100 ) > 1 ) ;
4242 }
4343 c . OnExecute ( ( ) => {
44- if ( TraceCommandAfterParse ) {
45- string introLine = String . Format ( "Executing {0}" , Command ) ;
44+
45+ try {
46+ if ( TraceCommandAfterParse ) {
47+ string introLine = String . Format ( "Executing {0}" , Command ) ;
4648
47- if ( ( OneLineDescription ? . Length ?? 0 ) == 0 ) {
48- introLine += String . Format ( " ({0})" , OneLineDescription ) ;
49- }
49+ if ( ( OneLineDescription ? . Length ?? 0 ) == 0 ) {
50+ introLine += String . Format ( " ({0})" , OneLineDescription ) ;
51+ }
5052
51- c . Out . WriteLine ( introLine ) ;
53+ c . Out . WriteLine ( introLine ) ;
5254
53- }
54- foreach ( var option in OptionsHasd )
55- {
56- option . Invoke ( ) ;
57- }
55+ }
56+ foreach ( var option in OptionsHasd )
57+ {
58+ option . Invoke ( ) ;
59+ }
5860
59- try {
6061 CheckRequiredArguments ( ) ;
62+
63+ if ( RemainingArgumentsCount != 0 ) {
64+ var actCount = ( remainingArgs ? . Values . Count ( ) ?? 0 ) ;
65+ if ( actCount < RemainingArgumentsCount ) {
66+ c . Out . WriteLine ( "Invalid number of arguments-- expected {1} more." , RemainingArgumentsCount - actCount ) ;
67+ c . ShowHelp ( ) ;
68+ return 2 ;
69+ }
70+ }
71+
72+ return Run ( remainingArgs ? . Values . ToArray ( ) ?? new string [ ] { } ) ;
73+
6174 } catch ( ConsoleHelpAsException ex ) {
6275 c . Out . WriteLine ( ex . Message ) ;
6376 c . ShowHelp ( ) ;
6477 return 2 ;
6578 }
6679
67- if ( RemainingArgumentsCount != 0 ) {
68- var actCount = ( remainingArgs ? . Values . Count ( ) ?? 0 ) ;
69- if ( actCount < RemainingArgumentsCount ) {
70- c . Out . WriteLine ( "Invalid number of arguments-- expected {1} more." , RemainingArgumentsCount - actCount ) ;
71- c . ShowHelp ( ) ;
72- return 2 ;
73- }
74- }
75-
76- return Run ( remainingArgs ? . Values . ToArray ( ) ?? new string [ ] { } ) ;
7780 } ) ;
7881 } ) ;
7982 }
0 commit comments