-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.cs
101 lines (83 loc) · 3.68 KB
/
Main.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
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
96
97
98
99
100
101
using System;
using System.IO;
using System.Collections.Generic;
using System.Xml;
namespace SimpleDocs
{
class MainClass
{
public static void Main(string[] args)
{
if (getArg(args, "Help") != null && (getArg(args, "Help") == "" || getArg(args, "Help").ToLower() == "true"))
{
Console.WriteLine();
Console.WriteLine("Execute SimpleDocs in folder containing documentation.");
Console.WriteLine("All files are searched for documentation.");
Console.WriteLine();
Console.WriteLine("Optional options:");
Console.WriteLine(" FileType=php Search only specified file type for documentation");
Console.WriteLine(" ResultFile=x.html Name of result file - defaults to SimpleDocs.html");
Console.WriteLine(" for HTML format and SimpleDocs.json for JSON format");
Console.WriteLine(" OutputFormat Output format: HTML (default) or JSON");
Console.WriteLine(" Recursively Search current folder and all sub folders recursively");
Console.WriteLine(" IncludePrivate Include private members and functions in documentation");
Console.WriteLine(" Help Display this help");
Console.WriteLine();
return;
}
string dir = System.Environment.CurrentDirectory;
string fileType = (getArg(args, "FileType") != null ? getArg(args, "FileType") : "");
string outputFormat = (getArg(args, "OutputFormat") != null && Array.Exists(new string[] { "HTML", "JSON" }, s => s == getArg(args, "OutputFormat").ToUpper()) == true ? getArg(args, "OutputFormat").ToUpper() : "HTML");
string filename = (getArg(args, "ResultFile") != null && getArg(args, "ResultFile") != "" ? getArg(args, "ResultFile") : "SimpleDocs." + (outputFormat == "JSON" ? "json" : "html"));
bool recursively = (getArg(args, "Recursively") != null && (getArg(args, "Recursively") == "" || getArg(args, "Recursively").ToLower() == "true"));
bool includePrivate = (getArg(args, "IncludePrivate") != null && (getArg(args, "IncludePrivate") == "" || getArg(args, "IncludePrivate").ToLower() == "true"));
string[] files = FileHandler.GetFiles(dir, fileType, recursively);
List<Container> containers = new List<Container>();
List<Member> members = new List<Member>();
List<Function> functions = new List<Function>();
string comments;
object[] elements;
foreach (string file in files)
{
Console.WriteLine("Processing " + file);
comments = FileHandler.GetCommentsFromFile(file);
elements = Parser.Parse(comments, includePrivate);
foreach (object element in elements)
{
if (element is Container)
containers.Add((Container)element);
else if (element is Member)
members.Add((Member)element);
else if (element is Function)
functions.Add((Function)element);
}
}
containers.Sort();
members.Sort();
functions.Sort();
Console.WriteLine("Generating documentation as " + outputFormat + " to " + filename);
Printer.PrintDocs(containers.ToArray(), members.ToArray(), functions.ToArray(), filename, outputFormat);
Console.WriteLine("Done - " + filename + " created");
}
private static string getArg(string[] args, string key)
{
string argument;
string[] argInfo;
foreach (string arg in args)
{
argument = arg;
argument = (argument.StartsWith("--") == true ? argument.Substring(2) : argument);
argument = (argument.StartsWith("-") == true ? argument.Substring(1) : argument);
argInfo = argument.Split(new char[] { '=' });
if (argInfo[0].ToLower().Equals(key.ToLower()) == true)
{
if (argInfo.Length > 1)
return argInfo[1];
else
return "";
}
}
return null;
}
}
}