@@ -15,17 +15,13 @@ class Program
15
15
{
16
16
static async Task Main ( string [ ] args )
17
17
{
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 )
22
19
{
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 ) ;
26
22
}
27
23
28
- const string outputDirectory = "../../../../../src/KubernetesClient/generated/" ;
24
+ var ( kubernetesBranch , outputDirectory ) = LoadSettings ( args [ 1 ] ) ;
29
25
30
26
var specUrl = $ "https://raw.githubusercontent.com/kubernetes/kubernetes/{ kubernetesBranch } /api/openapi-spec/swagger.json";
31
27
var specPath = $ "{ kubernetesBranch } -swagger.json";
@@ -102,6 +98,38 @@ static async Task Main(string[] args)
102
98
Render . FileToFile ( "ModelExtensions.cs.template" , definitions , $ "{ outputDirectory } ModelExtensions.cs") ;
103
99
}
104
100
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
+
105
133
static void ToXmlDoc ( RenderContext context , IList < object > arguments , IDictionary < string , object > options , RenderBlock fn , RenderBlock inverse )
106
134
{
107
135
if ( arguments != null && arguments . Count > 0 && arguments [ 0 ] != null && arguments [ 0 ] is string )
0 commit comments