forked from akiver/cs-demo-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
52 lines (46 loc) · 1.56 KB
/
Program.cs
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
using System;
using System.Threading.Tasks;
namespace CLI
{
internal class Program
{
public static string ExeName = AppDomain.CurrentDomain.FriendlyName;
private static readonly BaseCommand[] COMMANDS = { new AnalyzeCommand(), new DownloadCommand(), new JsonCommand(), new XlsxCommand() };
private static async Task Main(string[] args)
{
string commandName = "";
string[] commandArgs = Array.Empty<string>();
if (args.Length > 0)
{
commandName = args[0];
commandArgs = new string[args.Length - 1];
Array.Copy(args, 1, commandArgs, 0, commandArgs.Length);
}
BaseCommand command = GetCommandToRun(commandName);
if (command == null)
{
Console.WriteLine($@"{commandName}: unknown command");
Console.WriteLine($@"Run '{ExeName} help' for usage.");
}
else
{
await command.Run(commandArgs);
}
}
private static BaseCommand GetCommandToRun(string commandName)
{
if (commandName == "" || commandName == HelpCommand.COMMAND_NAME || commandName == "--help")
{
return new HelpCommand(COMMANDS);
}
foreach (BaseCommand command in COMMANDS)
{
if (command.GetName() == commandName)
{
return command;
}
}
return null;
}
}
}