Skip to content

Commit 191dfc9

Browse files
committed
Allow ref version for doc generation
This commit allows a reference version to be passed when generating documentation. The reference version is the version used in the link to the Elasticsearch reference documentation. (cherry picked from commit eea3887)
1 parent 7219697 commit 191dfc9

File tree

4 files changed

+58
-18
lines changed

4 files changed

+58
-18
lines changed

build/scripts/Commandline.fs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Execution hints can be provided anywhere on the command line
4444
- gendocs : generate documentation
4545
- non-interactive : make targets that run in interactive mode by default to run unassisted.
4646
- docs:<B> : the branch name B to use when generating documentation
47+
- ref:<B> : the reference version B to use when generating documentation
4748
- seed:<N> : provide a seed to run the tests with.
4849
- random:<K><:B> : sets random K to bool B if if B is omitted will default to true
4950
K can be: sourceserializer, typedkeys or oldconnection (only valid on windows)
@@ -95,6 +96,7 @@ Execution hints can be provided anywhere on the command line
9596
Seed: string;
9697
RandomArguments: string list;
9798
DocsBranch: string;
99+
ReferenceBranch: string;
98100
RemainingArguments: string list;
99101
MultiTarget: MultiTarget;
100102
Target: string;
@@ -123,7 +125,8 @@ Execution hints can be provided anywhere on the command line
123125
x <> "non-interactive" &&
124126
not (x.StartsWith("seed:")) &&
125127
not (x.StartsWith("random:")) &&
126-
not (x.StartsWith("docs:")))
128+
not (x.StartsWith("docs:")) &&
129+
not (x.StartsWith("ref:")))
127130
let target =
128131
match (filteredArgs |> List.tryHead) with
129132
| Some t -> t.Replace("-one", "")
@@ -146,6 +149,10 @@ Execution hints can be provided anywhere on the command line
146149
match args |> List.tryFind (fun x -> x.StartsWith("docs:")) with
147150
| Some t -> t.Replace("docs:", "")
148151
| _ -> ""
152+
ReferenceBranch =
153+
match args |> List.tryFind (fun x -> x.StartsWith("ref:")) with
154+
| Some t -> t.Replace("ref:", "")
155+
| _ -> ""
149156
RemainingArguments = filteredArgs
150157
MultiTarget =
151158
match (filteredArgs |> List.tryHead) with

build/scripts/Documentation.fs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,27 @@ open System.IO
44

55
open Projects
66
open Commandline
7+
open Fake.Core
78

89
module Documentation =
910

1011
let Generate args =
1112
let docGenerator = PrivateProject(DocGenerator)
1213
let path = Paths.ProjectOutputFolder docGenerator DotNetFramework.NetCoreApp2_1
13-
let generator = sprintf "%s.dll" docGenerator.Name
14+
let generator = sprintf "%s.dll" docGenerator.Name
1415

15-
Tooling.DotNet.ExecIn path [generator; args.DocsBranch] |> ignore
16+
let (|NotNullOrEmpty|_|) (candidate:string) =
17+
if String.isNotNullOrEmpty candidate then Some candidate
18+
else None
19+
20+
let dotnetArgs =
21+
match (args.DocsBranch, args.ReferenceBranch) with
22+
| (NotNullOrEmpty b, NotNullOrEmpty d) -> [ generator; "-b"; b; "-d"; d ];
23+
| (NotNullOrEmpty b, _) -> [ generator; "-b"; b ];
24+
| (_, NotNullOrEmpty d) -> [ generator; "-d"; d ];
25+
| (_, _) -> [ generator ]
26+
27+
Tooling.DotNet.ExecIn path dotnetArgs |> ignore
1628

1729
// TODO: hook documentation validation into the process
1830
let Validate() =

src/CodeGeneration/DocGenerator/DocGenerator.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
</PropertyGroup>
1111
<ItemGroup>
1212
<PackageReference Include="AsciiDocNet" Version="1.0.0-alpha6" />
13+
<PackageReference Include="CommandLineParser" Version="2.6.0" />
1314
<PackageReference Include="Microsoft.Build.Runtime" Version="15.7.179" />
1415
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.2" />
1516
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />

src/CodeGeneration/DocGenerator/Program.cs

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using System.Linq;
55
using System.Text.RegularExpressions;
6+
using CommandLine;
67

78
namespace DocGenerator
89
{
@@ -38,7 +39,7 @@ string P(string path)
3839
.Last().Value
3940
.Split(".")
4041
.Take(2));
41-
Console.WriteLine("Using global.json version: " + globalJsonVersion);
42+
4243
DocVersion = globalJsonVersion;
4344

4445
var process = new Process
@@ -88,22 +89,41 @@ string P(string path)
8889

8990
private static int Main(string[] args)
9091
{
91-
try
92-
{
93-
if (args.Length > 0)
94-
BranchName = args[0];
92+
return Parser.Default.ParseArguments<DocGeneratorOptions>(args)
93+
.MapResult(
94+
opts =>
95+
{
96+
try
97+
{
98+
if (!string.IsNullOrEmpty(opts.BranchName))
99+
BranchName = opts.BranchName;
95100

96-
Console.WriteLine($"Using branch name {BranchName} in documentation");
101+
if (!string.IsNullOrEmpty(opts.DocVersion))
102+
DocVersion = opts.DocVersion;
97103

98-
LitUp.GoAsync(args).Wait();
99-
return 0;
100-
}
101-
catch (AggregateException ae)
102-
{
103-
var ex = ae.InnerException ?? ae;
104-
Console.WriteLine(ex.Message);
105-
return 1;
106-
}
104+
Console.WriteLine($"Using branch name {BranchName} in documentation");
105+
Console.WriteLine($"Using doc reference version {DocVersion} in documentation");
106+
107+
LitUp.GoAsync(args).Wait();
108+
return 0;
109+
}
110+
catch (AggregateException ae)
111+
{
112+
var ex = ae.InnerException ?? ae;
113+
Console.WriteLine(ex.Message);
114+
return 1;
115+
}
116+
},
117+
errs => 1);
107118
}
108119
}
120+
121+
public class DocGeneratorOptions
122+
{
123+
[Option('b', "branch", Required = false, HelpText = "The version that appears in generated from source link")]
124+
public string BranchName { get; set; }
125+
126+
[Option('d', "docs", Required = false, HelpText = "The version that links to the Elasticsearch reference documentation")]
127+
public string DocVersion { get; set; }
128+
}
109129
}

0 commit comments

Comments
 (0)