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
72 lines (54 loc) · 2.26 KB
/
Program.cs
File metadata and controls
72 lines (54 loc) · 2.26 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
64
65
66
67
68
69
70
71
72
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)
.Cache(commandArgs.Cache)
.LogLevel(commandArgs.LogLevel)
.ScriptName(commandArgs.ScriptName)
.Repl(commandArgs.Repl);
var modules = GetModuleList(commandArgs.Modules);
var extension = Path.GetExtension(commandArgs.ScriptName);
if (string.IsNullOrWhiteSpace(extension) && !commandArgs.Repl)
{
extension = ".csx";
var scriptName = string.Format("{0}.csx", commandArgs.ScriptName);
if (!File.Exists(scriptName))
{
console.WriteLine(string.Format(
"Can't find a script named {0}",scriptName));
return 1;
}
commandArgs.ScriptName = scriptName;
}
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;
}
}
}