public static object Execute(CommandLineConfiguration config, params string[] args) { // Defensively copy the configuration into local variables var helpOutput = config.HelpOutput; _traceOutput = config.TraceOutput; var assembliesToScan = config.AssembliesToScan.ToList(); var typeConverters = new TypeConverterCollection(config.TypeConverters); var objectFactory = config.ObjectFactory; var commandLineArgs = CommandLineArgumentList.Parse(args); if (commandLineArgs.TraceToStandardOutput) { _traceOutput = helpOutput; } var model = AssemblyModel.Scan(assembliesToScan); var resolvedCommandLineActions = ResolveActions( objectFactory, typeConverters, commandLineArgs, model); if (IsReadyForExecution(commandLineArgs, resolvedCommandLineActions)) { var commandLineAction = resolvedCommandLineActions.Single(); try { return(commandLineAction.Invoke()); } catch (TypeConversionException e) { helpOutput(e.Message); _traceOutput(e.ToString()); return(null); } } else { var helpBuilder = new HelpBuilder(XmlCommentsRepository.LoadFor(assembliesToScan)); helpOutput( helpBuilder.GenerateHelp(commandLineArgs, model, resolvedCommandLineActions)); return(null); } }
public HelpBuilder(XmlCommentsRepository xmlComments) { _xmlComments = xmlComments; }