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
55 lines (44 loc) · 1.6 KB
/
Program.cs
File metadata and controls
55 lines (44 loc) · 1.6 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
using System;
using PowerArgs;
using ScriptCs.Command;
namespace ScriptCs
{
internal static class Program
{
private static int Main(string[] args)
{
var commandArgs = ParseArguments(args) ?? new ScriptCsArgs { Repl = true };
var compositionRoot = new CompositionRoot(commandArgs);
compositionRoot.Initialize();
var logger = compositionRoot.GetLogger();
logger.Debug("Creating ScriptServiceRoot");
var scriptServiceRoot = compositionRoot.GetServiceRoot();
var commandFactory = new CommandFactory(scriptServiceRoot);
var command = commandFactory.CreateCommand(commandArgs);
var result = command.Execute();
return result == CommandResult.Success ? 0 : -1;
}
private static ScriptCsArgs ParseArguments(string[] args)
{
const string UnexpectedArgumentMessage = "Unexpected Argument: ";
if (args.Length <= 0) return null;
try
{
return Args.Parse<ScriptCsArgs>(args);
}
catch (ArgException ex)
{
if (ex.Message.StartsWith(UnexpectedArgumentMessage))
{
var token = ex.Message.Substring(UnexpectedArgumentMessage.Length);
Console.WriteLine("Parameter \"{0}\" is not supported!", token);
}
else
{
Console.WriteLine(ex.Message);
}
}
return new ScriptCsArgs();
}
}
}