-
Notifications
You must be signed in to change notification settings - Fork 2
/
Parser.cs
68 lines (59 loc) · 2.47 KB
/
Parser.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
namespace Grab
{
static class Parser
{
static IProvider Provider;
internal static void Parse(string[] args)
{
if (args.Length == 0)
{
ShowHelp();
return;
}
ShowVersion();
RunProvider(args);
}
static void RunProvider(string[] packages)
{
Provider = new NuGetProvider();
var Downloads = Provider.DownloadPackages(packages)
.Select(async p =>
{
var (name, isSuccess, msg) = await p;
var color = isSuccess ? ConsoleColor.Green : ConsoleColor.Red;
Console.ForegroundColor = color;
Console.WriteLine($" {name} - {msg}");
}).ToArray();
Task.WaitAll(Downloads);
Console.ResetColor();
Console.WriteLine();
}
static void ShowVersion()
{
var versionString = Assembly.GetEntryAssembly()
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
.InformationalVersion
.ToString();
Console.WriteLine($"{Constants.APP_NAME} v{versionString}");
Console.WriteLine("----------------");
}
static void ShowHelp()
{
ShowVersion();
Console.WriteLine($"\nUsage: {Constants.APP_NAME} [packages...]");
Console.WriteLine("\npackages:");
Console.WriteLine(" list of packages names (@ optional versions) to download");
Console.WriteLine("\nEx:");
Console.WriteLine($" {Constants.APP_NAME} newtonsoft.json [email protected] [email protected]");
Console.WriteLine("\n newtonsoft.json @ 12.0.3 - downloaded");
Console.WriteLine(" newtonsoft.json @ 6.0.7 - downloaded");
Console.WriteLine(" entityframework @ 6.2.0 - downloaded");
Console.WriteLine("\npackages are saved under 'packages' in current directory");
Console.WriteLine();
}
}
}