This repository was archived by the owner on Jan 1, 2021. It is now read-only.
forked from elastic/elasticsearch-net
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
101 lines (81 loc) · 2.78 KB
/
Copy pathProgram.cs
File metadata and controls
101 lines (81 loc) · 2.78 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
96
97
98
99
100
101
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information
using System;
using System.IO;
using System.Linq;
using CommandLine;
using Newtonsoft.Json.Linq;
namespace DocGenerator
{
public static class Program
{
static Program()
{
var root = new DirectoryInfo(Directory.GetCurrentDirectory());
do
{
if (File.Exists(Path.Combine(root.FullName, "global.json")))
break;
root = root.Parent;
} while (root != null && root.Parent != root.Root);
if (root == null || root.Parent == root.Root)
throw new Exception("Expected to find a global.json in a parent folder");
var r = root.FullName;
var globalJson = Path.Combine(r, "global.json");
InputDirPath = Path.Combine(r, "src");
OutputDirPath = Path.Combine(r, "docs");
TmpOutputDirPath = Path.Combine(r, "docs-temp");
var jObject = JObject.Parse(File.ReadAllText(globalJson));
DocVersion = string.Join(".", jObject["doc_current"]
.Value<string>()
.Split(".")
.Take(2));
BranchName =
jObject.ContainsKey("doc_branch")
? jObject["doc_branch"].Value<string>()
: "master";
}
/// <summary>
/// The branch name to include in generated docs to link back to the original source file
/// </summary>
public static string BranchName { get; private set; }
/// <summary>
/// The Elasticsearch documentation version to link to
/// </summary>
public static string DocVersion { get; private set; }
public static string InputDirPath { get; }
public static string OutputDirPath { get; }
public static string TmpOutputDirPath { get; }
private static int Main(string[] args) =>
Parser.Default.ParseArguments<DocGeneratorOptions>(args)
.MapResult(
opts =>
{
try
{
if (!string.IsNullOrEmpty(opts.BranchName))
BranchName = opts.BranchName;
if (!string.IsNullOrEmpty(opts.DocVersion))
DocVersion = opts.DocVersion;
Console.WriteLine($"Using branch name {BranchName} in documentation");
Console.WriteLine($"Using doc reference version {DocVersion} in documentation");
return LitUp.GoAsync(args).GetAwaiter().GetResult();
}
catch (AggregateException ae)
{
var ex = ae.InnerException ?? ae;
Console.WriteLine(ex.Message);
return 1;
}
},
errs => 1);
}
public class DocGeneratorOptions
{
[Option('b', "branch", Required = false, HelpText = "The version that appears in generated from source link")]
public string BranchName { get; set; }
[Option('d', "docs", Required = false, HelpText = "The version that links to the Elasticsearch reference documentation")]
public string DocVersion { get; set; }
}
}