-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathReadme.cs
More file actions
57 lines (50 loc) · 1.61 KB
/
Readme.cs
File metadata and controls
57 lines (50 loc) · 1.61 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
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
namespace Https.Tests
{
public class Readme
{
public string InstallationVersion { get; }
public string UsageDocumentation { get; }
public Readme(string path)
{
if (string.IsNullOrWhiteSpace(path)) throw new ArgumentNullException(nameof(path));
var sb = new StringBuilder();
InstallationVersion = "";
UsageDocumentation = "";
var lines = File.ReadLines(path);
var record = false;
foreach (var line in lines)
{
if (line.StartsWith("```bash"))
{
record = true;
}
else if (line.StartsWith("```"))
{
var text = sb.ToString();
sb.Clear();
if (text.StartsWith("dotnet tool"))
{
var match = Regex.Match(text, "dotnet tool install --global https --version (.+)-\\*");
if (match.Success)
{
InstallationVersion = match.Groups[1].Value;
}
}
else if (text.StartsWith("Usage"))
{
UsageDocumentation = text;
}
record = false;
}
else if (record)
{
sb.AppendLine(line);
}
}
}
}
}