@@ -25,16 +25,49 @@ public void Interpret(string[] args)
2525 {
2626 if ( options == null )
2727 Environment . Exit ( CommandLine . Parser . DefaultExitCodeFail ) ;
28+
29+ // Get possible types from plugin assembly.
2830 var targetAssembly = Assembly . LoadFrom ( options . PlugInName + ".dll" ) ;
2931 var types = targetAssembly . GetTypes ( ) ;
30- var optionType = types . FirstOrDefault ( x => typeof ( IOptions ) . IsAssignableFrom ( x ) ) ;
32+ var optionType = types . FirstOrDefault ( x => x . IsClass && typeof ( IOptions ) . IsAssignableFrom ( x ) ) ;
3133 if ( optionType == null )
3234 Environment . Exit ( CommandLine . Parser . DefaultExitCodeFail ) ;
35+
36+ // Create an instance of the plugin's options class.
3337 var pluginOptions = targetAssembly . CreateInstance ( optionType . FullName ) as IOptions ;
34- var isSuccessful = CommandLine
35- . Parser
36- . Default
37- . ParseArguments ( args . Skip ( 1 ) . ToArray ( ) , pluginOptions , ( verb , subOptions ) =>
38+
39+ // If the plugin's args are empty, print the plugin's help screen and exit.
40+ var pluginArgs = args . Skip ( 1 ) . ToArray ( ) ;
41+ if ( ! pluginArgs . ToList ( ) . Any ( ) ) {
42+ CommandLine . Parser . Default . ParseArguments ( pluginArgs , pluginOptions ) ;
43+ Console . WriteLine ( pluginOptions . GetUsage ( "" ) ) ;
44+ ExitWithSuccess ( ) ;
45+ }
46+
47+ InterpretPluginArguments ( pluginArgs , pluginOptions ) ;
48+ }
49+ }
50+
51+ public void ExitWithSuccess ( string message = null )
52+ {
53+ if ( string . IsNullOrWhiteSpace ( message ) )
54+ message = "success" ;
55+ Logger . Debug ( $ "✔ { message } ") ;
56+ Environment . Exit ( 0 ) ;
57+ }
58+
59+ public void ExitWithFailure ( Exception exception = null )
60+ {
61+ Logger . Error ( exception ?? new CommandFailedException ( ) , "✘ fail" ) ;
62+ Environment . Exit ( CommandLine . Parser . DefaultExitCodeFail ) ;
63+ }
64+
65+ public void InterpretPluginArguments ( string [ ] pluginArgs , IOptions pluginOptions )
66+ {
67+ var isSuccessful = CommandLine
68+ . Parser
69+ . Default
70+ . ParseArguments ( pluginArgs , pluginOptions , ( verb , subOptions ) =>
3871 {
3972 try
4073 {
@@ -59,23 +92,8 @@ public void Interpret(string[] args)
5992 }
6093 } ) ;
6194
62- if ( ! isSuccessful )
63- ExitWithFailure ( ) ;
64- }
65- }
66-
67- public void ExitWithSuccess ( string message )
68- {
69- if ( string . IsNullOrWhiteSpace ( message ) )
70- message = "success" ;
71- Logger . Debug ( $ "✔ { message } ") ;
72- Environment . Exit ( 0 ) ;
73- }
74-
75- public void ExitWithFailure ( Exception exception = null )
76- {
77- Logger . Error ( exception != null ? exception : new CommandFailedException ( ) , "✘ fail" ) ;
78- Environment . Exit ( CommandLine . Parser . DefaultExitCodeFail ) ;
95+ if ( ! isSuccessful )
96+ ExitWithFailure ( ) ;
7997 }
8098 }
8199}
0 commit comments