forked from EvilBeaver/OneScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
88 lines (75 loc) · 2.99 KB
/
Program.cs
File metadata and controls
88 lines (75 loc) · 2.99 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
/*----------------------------------------------------------
This Source Code Form is subject to the terms of the
Mozilla Public License, v.2.0. If a copy of the MPL
was not distributed with this file, You can obtain one
at http://mozilla.org/MPL/2.0/.
----------------------------------------------------------*/
using System;
using System.Linq;
using CommandLine;
using OneScriptDocumenter.Cli;
using OneScriptDocumenter.Model;
using OneScriptDocumenter.Primary;
using OneScriptDocumenter.Secondary;
using MarkdownGenerator = OneScriptDocumenter.Cli.MarkdownGenerator;
namespace OneScriptDocumenter
{
public static class Program
{
public static int Main(string[] args)
{
var parserResult = Parser.Default.ParseArguments<GeneratorOptions>(args);
switch (parserResult.Tag)
{
case ParserResultType.Parsed:
try
{
return ProcessOptions(parserResult.Value);
}
catch(Exception e)
{
ConsoleLogger.Error(e.ToString());
return 1;
}
default:
return 1;
}
}
private static int ProcessOptions(GeneratorOptions options)
{
if (string.IsNullOrEmpty(options.JsonFile) && string.IsNullOrEmpty(options.MarkdownDir))
{
ConsoleLogger.Error("Must have either --json or --markdown options");
return 1;
}
var primaryGenerator = new PrimaryDocsCollector();
var primaryDocs = primaryGenerator.Collect(options.AssemblyFiles.ToList());
var refFactory = new ReferenceFactory();
var referenceResolver = new MarkdownReferenceResolver(primaryDocs.ReferenceCollector, refFactory);
var tocFile = options.TocFile;
var docBuilder = new DocumentationModelBuilder(primaryDocs, referenceResolver, tocFile);
var secondaryDocs = docBuilder.Build();
if (!string.IsNullOrEmpty(options.JsonFile))
{
WriteJson(secondaryDocs, options.JsonFile);
}
if (!string.IsNullOrEmpty(options.MarkdownDir))
{
WriteMarkdown(secondaryDocs, options.MarkdownDir);
}
ConsoleLogger.Info("Generation completed");
return 0;
}
private static void WriteMarkdown(DocumentationModel documentation, string outputDir)
{
var refFactory = new ReferenceFactory();
var mdGenerator = new MarkdownGenerator(documentation, refFactory);
mdGenerator.Write(outputDir);
}
private static void WriteJson(DocumentationModel documentation, string outputFile)
{
var jsonWriter = new JsonGenerator(documentation);
jsonWriter.WriteFile(outputFile);
}
}
}