Skip to content

Commit 7f6043a

Browse files
tg123k8s-ci-robot
authored andcommitted
generator cmd param (#252)
1 parent de99b2b commit 7f6043a

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

gen/KubernetesWatchGenerator/Program.cs

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,13 @@ class Program
1515
{
1616
static async Task Main(string[] args)
1717
{
18-
// Initialize variables - such as the Kubernetes branch for which to generate the API.
19-
string kubernetesBranch = "v1.10.0";
20-
21-
if (Environment.GetEnvironmentVariable("KUBERNETES_BRANCH") != null)
18+
if (args.Length < 2)
2219
{
23-
kubernetesBranch = Environment.GetEnvironmentVariable("KUBERNETES_BRANCH");
24-
25-
Console.WriteLine($"Using Kubernetes branch {kubernetesBranch}, as set by the KUBERNETES_BRANCH environment variable");
20+
Console.Error.WriteLine($"usage {args[0]} path/to/csharp.settings");
21+
Environment.Exit(1);
2622
}
2723

28-
const string outputDirectory = "../../../../../src/KubernetesClient/generated/";
24+
var (kubernetesBranch, outputDirectory) = LoadSettings(args[1]);
2925

3026
var specUrl = $"https://raw.githubusercontent.com/kubernetes/kubernetes/{kubernetesBranch}/api/openapi-spec/swagger.json";
3127
var specPath = $"{kubernetesBranch}-swagger.json";
@@ -102,6 +98,38 @@ static async Task Main(string[] args)
10298
Render.FileToFile("ModelExtensions.cs.template", definitions, $"{outputDirectory}ModelExtensions.cs");
10399
}
104100

101+
private static (string kubernetesBranch, string outputDirectory) LoadSettings(string path)
102+
{
103+
var fileInfo = new FileInfo(path);
104+
105+
if (!fileInfo.Exists)
106+
{
107+
Console.Error.WriteLine("Cannot find csharp.settings");
108+
Environment.Exit(1);
109+
}
110+
111+
using (var s = new StreamReader(fileInfo.OpenRead()))
112+
{
113+
string l;
114+
while ((l = s.ReadLine()) != null)
115+
{
116+
if (l.Contains("KUBERNETES_BRANCH"))
117+
{
118+
var kubernetesBranch = l.Split("=")[1];
119+
var outputDirectory = Path.Combine(fileInfo.DirectoryName, @"src/KubernetesClient/generated/");
120+
121+
Console.WriteLine($"Using branch {kubernetesBranch} output {outputDirectory}");
122+
123+
return (kubernetesBranch, outputDirectory);
124+
}
125+
}
126+
}
127+
128+
Console.Error.WriteLine("Cannot find KUBERNETES_BRANCH in csharp.settings");
129+
Environment.Exit(1);
130+
return (null, null);
131+
}
132+
105133
static void ToXmlDoc(RenderContext context, IList<object> arguments, IDictionary<string, object> options, RenderBlock fn, RenderBlock inverse)
106134
{
107135
if (arguments != null && arguments.Count > 0 && arguments[0] != null && arguments[0] is string)

0 commit comments

Comments
 (0)