private static int Main(string[] args) { SetProfile(); ArgumentParseResult arguments; var console = new ScriptConsole(); try { var parser = new ArgumentHandler(new ArgumentParser(), new ConfigFileParser(console), new FileSystem()); arguments = parser.Parse(args); } catch (Exception ex) { console.WriteLine(ex.Message); var options = new ArgUsageOptions { ShowPosition = false, ShowType = false }; var usage = ArgUsage.GetUsage <ScriptCsArgs>(options: options); console.WriteLine(usage); return(1); } finally { console.Exit(); } var scriptServicesBuilder = ScriptServicesBuilderFactory.Create(arguments.CommandArguments, arguments.ScriptArguments); var factory = new CommandFactory(scriptServicesBuilder); var command = factory.CreateCommand(arguments.CommandArguments, arguments.ScriptArguments); return((int)command.Execute()); }
private static int Main(string[] args) { var console = new ScriptConsole(); var parser = new ArgumentHandler(new ArgumentParser(console), new ConfigFileParser(console), new FileSystem()); var arguments = parser.Parse(args); var commandArgs = arguments.CommandArguments; var scriptArgs = arguments.ScriptArguments; var configurator = new LoggerConfigurator(commandArgs.LogLevel); configurator.Configure(console); var logger = configurator.GetLogger(); var scriptServicesBuilder = new ScriptServicesBuilder(console, logger) .InMemory(commandArgs.InMemory) .LogLevel(commandArgs.LogLevel) .ScriptName(commandArgs.ScriptName) .Repl(commandArgs.Repl); var modules = GetModuleList(commandArgs.Modules); var extension = Path.GetExtension(commandArgs.ScriptName); if (!string.IsNullOrWhiteSpace(extension)) { extension = extension.Substring(1); } else if (extension == string.Empty) { console.WriteLine(string.Format("{0} is not a valid script name.", commandArgs.ScriptName)); return(1); } scriptServicesBuilder.LoadModules(extension, modules); var scriptServiceRoot = scriptServicesBuilder.Build(); var commandFactory = new CommandFactory(scriptServiceRoot); var command = commandFactory.CreateCommand(commandArgs, scriptArgs); var result = command.Execute(); return(result == CommandResult.Success ? 0 : -1); }
private static int Main(string[] args) { var console = new ScriptConsole(); var parser = new ArgumentHandler(new ArgumentParser(console), new ConfigFileParser(console), new FileSystem()); var arguments = parser.Parse(args); var commandArgs = arguments.CommandArguments; var scriptArgs = arguments.ScriptArguments; var configurator = new LoggerConfigurator(commandArgs.LogLevel); configurator.Configure(console); var logger = configurator.GetLogger(); var scriptServicesBuilder = new ScriptServicesBuilder(console, logger) .InMemory(commandArgs.InMemory) .LogLevel(commandArgs.LogLevel) .ScriptName(commandArgs.ScriptName) .Repl(commandArgs.Repl); var modules = GetModuleList(commandArgs.Modules); var extension = Path.GetExtension(commandArgs.ScriptName); if (!string.IsNullOrWhiteSpace(extension)) { extension = extension.Substring(1); } else if (extension == string.Empty) { console.WriteLine(string.Format("{0} is not a valid script name.", commandArgs.ScriptName)); return 1; } scriptServicesBuilder.LoadModules(extension, modules); var scriptServiceRoot = scriptServicesBuilder.Build(); var commandFactory = new CommandFactory(scriptServiceRoot); var command = commandFactory.CreateCommand(commandArgs, scriptArgs); var result = command.Execute(); return result == CommandResult.Success ? 0 : -1; }