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
79 lines (62 loc) · 2.91 KB
/
Program.cs
File metadata and controls
79 lines (62 loc) · 2.91 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
73
74
75
76
77
78
79
using System.IO;
using System.Runtime;
using ScriptCs.Argument;
using ScriptCs.Command;
namespace ScriptCs
{
internal static class Program
{
private static int Main(string[] args)
{
ProfileOptimization.SetProfileRoot(typeof(Program).Assembly.Location);
ProfileOptimization.StartProfile(typeof(Program).Assembly.GetName().Name + ".profile");
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)
{
// No extension was given, i.e we might have something like
// "scriptcs foo" to deal with. We activate the default extension,
// to make sure it's given to the LoadModules below.
extension = ".csx";
if (!string.IsNullOrWhiteSpace(commandArgs.ScriptName))
{
// If the was in fact a script specified, we'll extend it
// with the default extension, assuming the user giving
// "scriptcs foo" actually meant "scriptcs foo.csx". We
// perform no validation here thought; let it be done by
// the activated command. If the file don't exist, it's
// up to the command to detect and report.
commandArgs.ScriptName += extension;
}
}
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;
}
}
}