@@ -20,10 +20,11 @@ public ArgumentInterpreter()
2020
2121 public void Interpret ( string [ ] args )
2222 {
23+ var plugins = FindPlugins ( ) ;
2324 if ( ! args . Any ( ) )
2425 {
2526 Console . WriteLine ( "Available plugins... " ) ;
26- FindPlugins ( ) . ForEach ( x => Console . WriteLine ( x . Name ) ) ;
27+ plugins . ForEach ( x => Console . WriteLine ( x . Name ) ) ;
2728 ExitWithSuccess ( ) ;
2829 }
2930
@@ -34,23 +35,11 @@ public void Interpret(string[] args)
3435 {
3536 if ( options == null )
3637 Environment . Exit ( CommandLine . Parser . DefaultExitCodeFail ) ;
37-
38- // Get plugins.
39- // If no arg is specified, list plugins
40-
41- // Get possible types from plugin assembly.
42- var targetAssembly = Assembly . LoadFrom ( options . PlugInName + ".dll" ) ;
43- var types = targetAssembly . GetTypes ( ) ;
44- var optionType = types . FirstOrDefault ( x => x . IsClass && typeof ( IOptions ) . IsAssignableFrom ( x ) ) ;
45- if ( optionType == null )
46- Environment . Exit ( CommandLine . Parser . DefaultExitCodeFail ) ;
47-
48- // Create an instance of the plugin's options class.
49- var pluginOptions = targetAssembly . CreateInstance ( optionType . FullName ) as IOptions ;
50-
51- // If the plugin's args are empty, print the plugin's help screen and exit.
38+
39+ var pluginOptions = plugins . FirstOrDefault ( x => x . Name == options . PlugInName ) . MakeOptions ( ) ;
5240 var pluginArgs = args . Skip ( 1 ) . ToArray ( ) ;
5341 if ( ! pluginArgs . ToList ( ) . Any ( ) ) {
42+ // If the plugin's args are empty, print the plugin's help screen and exit.
5443 CommandLine . Parser . Default . ParseArguments ( pluginArgs , pluginOptions ) ;
5544 Console . WriteLine ( pluginOptions . GetUsage ( "" ) ) ;
5645 ExitWithSuccess ( ) ;
0 commit comments