@@ -46,30 +46,7 @@ public Arguments ParseArguments(string commandLineArguments) =>
4646
4747 public Arguments ParseArguments ( string [ ] commandLineArguments )
4848 {
49- if ( commandLineArguments . Length == 0 )
50- {
51- var args = new Arguments { TargetPath = SysEnv . CurrentDirectory } ;
52- args . Output . Add ( OutputType . Json ) ;
53- AddAuthentication ( args ) ;
54- return args ;
55- }
56-
5749 var ( rootCommand , options ) = commandFactory . Value ;
58-
59- // Let System.CommandLine handle --help output natively
60- if ( commandLineArguments . Any ( a => a is "--help" or "-h" ) )
61- {
62- PrintBuiltInHelp ( rootCommand ) ;
63- return new Arguments { IsHelp = true } ;
64- }
65-
66- // Handle --version before parsing to avoid System.CommandLine interception
67- if ( commandLineArguments . Any ( a => a is "--version" ) )
68- {
69- PrintBuiltInVersion ( ) ;
70- return new Arguments { IsVersion = true } ;
71- }
72-
7350 var parseResult = rootCommand . Parse ( commandLineArguments ) ;
7451
7552 if ( parseResult . Errors . Count > 0 )
@@ -92,6 +69,17 @@ public Arguments ParseArguments(string[] commandLineArguments)
9269 throw new WarningException ( $ "Could not parse command line parameter '{ positionalCheck } '.") ;
9370 }
9471
72+ if ( IsOptionExplicitlySet < HelpOption > ( ) )
73+ {
74+ parseResult . Invoke ( ) ;
75+ return new Arguments { IsHelp = true } ;
76+ }
77+ if ( IsOptionExplicitlySet < VersionOption > ( ) )
78+ {
79+ parseResult . Invoke ( ) ;
80+ return new Arguments { IsVersion = true } ;
81+ }
82+
9583 var arguments = new Arguments ( ) ;
9684 AddAuthentication ( arguments ) ;
9785 MapParsedValues ( arguments , parseResult , options ) ;
@@ -117,24 +105,11 @@ public Arguments ParseArguments(string[] commandLineArguments)
117105 ValidateConfigurationFile ( arguments ) ;
118106
119107 return arguments ;
120- }
121-
122- private static void PrintBuiltInHelp ( RootCommand rootCommand )
123- {
124- rootCommand . SetAction ( ( _ , _ ) => Task . FromResult ( 0 ) ) ;
125- rootCommand . Parse ( [ "--help" ] ) . Invoke ( ) ;
126- }
127108
128- private void PrintBuiltInVersion ( )
129- {
130- var assembly = Assembly . GetExecutingAssembly ( ) ;
131- var version = assembly . GetCustomAttributes ( typeof ( AssemblyInformationalVersionAttribute ) , false )
132- . FirstOrDefault ( ) is AssemblyInformationalVersionAttribute attr
133- ? attr . InformationalVersion
134- : assembly . GetName ( ) . Version ? . ToString ( ) ;
135- if ( version != null )
136- {
137- this . console . WriteLine ( version ) ;
109+ bool IsOptionExplicitlySet < T > ( ) where T : Option
110+ {
111+ var option = rootCommand . Options . SingleOfType < T > ( ) ;
112+ return parseResult . GetResult ( option ) is { Implicit : false } ;
138113 }
139114 }
140115
0 commit comments