forked from scriptcs/scriptcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
63 lines (51 loc) · 2.08 KB
/
Program.cs
File metadata and controls
63 lines (51 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System.IO;
using ScriptCs.Argument;
using ScriptCs.Command;
namespace ScriptCs
{
internal static class Program
{
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 string[] GetModuleList(string modulesArg)
{
var modules = new string[0];
if (modulesArg != null)
{
modules = modulesArg.Split(',');
}
return modules;
}
}
}