forked from scriptcs/scriptcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.cs
More file actions
106 lines (82 loc) · 3.08 KB
/
Config.cs
File metadata and controls
106 lines (82 loc) · 3.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using ScriptCs.Contracts;
using System.IO;
namespace ScriptCs
{
// NOTE (Adam): passed across app domains as a property of CrossAppDomainExecuteScriptCommand
[Serializable]
public class Config
{
private string[] _modules;
public Config()
{
LogLevel = LogLevel.Info;
}
// global
public LogLevel LogLevel { get; set; }
public string[] Modules
{
get => _modules ?? new string[0];
set => _modules = value;
}
public string OutputFile { get; set; }
// clean command
public bool Clean { get; set; }
// install command
public bool AllowPreRelease { get; set; }
public bool Global { get; set; }
public string PackageName { get; set; }
public string PackageVersion { get; set; }
// save command
public bool Save { get; set; }
// run command
public string ScriptName { get; set; }
public bool Cache { get; set; }
public bool Debug { get; set; }
public bool Repl { get; set; }
public bool Watch { get; set; }
public string Eval { get; set; }
public static Config Create(string maskFile, ConfigMask configMask)
{
Guard.AgainstNullArgument("configMask", configMask);
return new Config()
.Apply(ConfigMask.ReadGlobalOrDefault())
.Apply(maskFile == null ? ConfigMask.ReadLocalOrDefault() : ConfigMask.Read(maskFile))
.Apply(configMask);
}
public Config Apply(ConfigMask mask)
{
if (mask == null)
{
return this;
}
var logLevel = mask.Debug.GetValueOrDefault() && !mask.LogLevel.HasValue && LogLevel != LogLevel.Trace
? LogLevel.Debug
: mask.LogLevel;
var modules = mask.Modules == null
? null
: mask.Modules.Split(new[] {","}, StringSplitOptions.RemoveEmptyEntries);
var scriptName = mask.ScriptName != null && !Path.GetFileName(mask.ScriptName).Contains(".")
? Path.ChangeExtension(mask.ScriptName, "csx")
: mask.ScriptName;
return new Config
{
LogLevel = logLevel ?? LogLevel,
_modules = modules ?? _modules,
OutputFile = mask.Output ?? OutputFile,
Clean = mask.Clean ?? Clean,
AllowPreRelease = mask.AllowPreRelease ?? AllowPreRelease,
Global = mask.Global ?? Global,
PackageName = mask.Install ?? PackageName,
PackageVersion = mask.PackageVersion ?? PackageVersion,
Save = mask.Save ?? Save,
Cache = mask.Cache ?? Cache,
Debug = mask.Debug ?? Debug,
Repl = mask.Repl ?? Repl,
ScriptName = scriptName ?? ScriptName,
Eval = mask.Eval ?? Eval,
Watch = mask.Watch ?? Watch,
};
}
}
}