-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
95 lines (89 loc) · 2.53 KB
/
Program.cs
File metadata and controls
95 lines (89 loc) · 2.53 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
using System;
using System.IO;
using System.Net.Security;
using System.Numerics;
using System.Runtime.CompilerServices;
using static System.Net.WebRequestMethods;
List<string> submods = [];
var rootPath = args[0];
int thisLevel = 0;
List<Repo> Repos = [];
var options = new EnumerationOptions
{
IgnoreInaccessible = true,
RecurseSubdirectories = true
};
foreach (string fileName in Directory.EnumerateFiles(rootPath, ".gitmodules", options))
{
var relFilePath = Path.GetDirectoryName(fileName[rootPath.Length..]);
if (relFilePath.Length > 1)
{
relFilePath += "\\";
}
for (int i = Repos.Count - 1; i > -1; i--)
{
if (!relFilePath.StartsWith(Repos[i].Path))
{
continue;
}
thisLevel = Repos[i].Level + 1;
break;
}
Repo thisRepo = new(relFilePath, thisLevel);
Repos.Add(thisRepo);
List<string> allLinesText = System.IO.File.ReadAllLines(fileName).ToList();
string submodName = "";
string submodPath = "";
string submodURL = "";
foreach (var fileline in allLinesText)
{
if (fileline.Contains("[submodule"))
{
submodName = fileline[(fileline.IndexOf("\"") + 1)..];
submodName = submodName.TrimEnd();
submodName = submodName.Remove(submodName.Length-2);
}
if (fileline.Contains("url"))
{
submodURL = fileline[(fileline.IndexOf("=") + 1)..];
submodURL = submodURL.Trim();
}
if (fileline.Contains("path"))
{
submodPath = fileline[(fileline.IndexOf("=") + 1)..];
submodPath = submodPath.Trim();
}
if (!string.IsNullOrEmpty(submodName) && !string.IsNullOrEmpty(submodURL) && !string.IsNullOrEmpty(submodPath))
{
var subModDetails = $"{relFilePath}{submodPath} ({submodName} {submodURL})";
subModDetails = subModDetails.Replace("/","\\");
Repo thisSubRepo = new(subModDetails, thisLevel);
Repos.Add(thisSubRepo);
submodName = "";
submodPath = "";
submodURL = "";
}
}
}
var orderedList = Repos.OrderBy(x => x.Path).ToList();
foreach (var currRepo in orderedList)
{
if (!(currRepo.Path.Contains("("))) {
if (currRepo.Level == 0)
{
// First level, show as heading
Console.WriteLine($"# {currRepo.Path}");
}
continue;
}
String md = "";
for (var i = 0; i < currRepo.Level; i++) { md += " "; }
if (currRepo.Path.Contains(".com"))
{
// Italize anything that refers to .com repo
Console.WriteLine($"{md}- _{currRepo.Path}_");
} else
{
Console.WriteLine($"{md}- {currRepo.Path}");
}
}