forked from scriptcs/scriptcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptServicesBuilderFactory.cs
More file actions
63 lines (53 loc) · 2.57 KB
/
ScriptServicesBuilderFactory.cs
File metadata and controls
63 lines (53 loc) · 2.57 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;
using System.IO;
using ScriptCs.Contracts;
using ScriptCs.Hosting;
namespace ScriptCs
{
public static class ScriptServicesBuilderFactory
{
public static IScriptServicesBuilder Create(ScriptCsArgs commandArgs, string[] scriptArgs)
{
Guard.AgainstNullArgument("commandArgs", commandArgs);
Guard.AgainstNullArgument("scriptArgs", scriptArgs);
IConsole console = new ScriptConsole();
if (!string.IsNullOrWhiteSpace(commandArgs.Output))
{
console = new FileConsole(commandArgs.Output, console);
}
var configurator = new LoggerConfigurator(commandArgs.LogLevel);
configurator.Configure(console);
var logger = configurator.GetLogger();
var initializationServices = new InitializationServices(logger);
initializationServices.GetAppDomainAssemblyResolver().Initialize();
var scriptServicesBuilder = new ScriptServicesBuilder(console, logger, null, null, initializationServices)
.Cache(commandArgs.Cache)
.Debug(commandArgs.Debug)
.LogLevel(commandArgs.LogLevel)
.ScriptName(commandArgs.ScriptName)
.Repl(commandArgs.Repl);
var modules = commandArgs.Modules == null
? new string[0]
: commandArgs.Modules.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
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;
}
}
return scriptServicesBuilder.LoadModules(extension, modules);
}
}
}