@@ -156,126 +156,57 @@ public bool IsInternalFromImage(string fromImage)
156
156
return _internalRepos . Any ( repo => fromImage . StartsWith ( $ "{ repo } :") ) ;
157
157
}
158
158
159
- public string GetOSDisplayName ( )
159
+ public string GetOSDisplayName ( ) => Model . OS switch
160
160
{
161
- string displayName ;
162
- string os = BaseOsVersion ;
161
+ OS . Windows => GetWindowsOSDisplayName ( BaseOsVersion ) ,
162
+ _ => GetLinuxOSDisplayName ( BaseOsVersion )
163
+ } ;
163
164
164
- if ( Model . OS == OS . Windows )
165
- {
166
- string version = os . Split ( '-' ) [ 1 ] ;
167
- if ( os . StartsWith ( "nanoserver" ) )
168
- {
169
- displayName = GetWindowsVersionDisplayName ( "Nano Server" , version ) ;
170
- }
171
- else if ( os . StartsWith ( "windowsservercore" ) )
172
- {
173
- displayName = GetWindowsVersionDisplayName ( "Windows Server Core" , version ) ;
174
- }
175
- else
176
- {
177
- throw new NotSupportedException ( $ "The OS version '{ os } ' is not supported.") ;
178
- }
179
- }
180
- else
165
+ private static string GetWindowsOSDisplayName ( string os )
166
+ {
167
+ string version = os . Split ( '-' ) [ 1 ] ;
168
+ return os switch
181
169
{
182
- if ( os . Contains ( "debian" ) )
183
- {
184
- displayName = "Debian" ;
185
- }
186
- else if ( os . Contains ( "jessie" ) )
187
- {
188
- displayName = "Debian 8" ;
189
- }
190
- else if ( os . Contains ( "stretch" ) )
191
- {
192
- displayName = "Debian 9" ;
193
- }
194
- else if ( os . Contains ( "buster" ) )
195
- {
196
- displayName = "Debian 10" ;
197
- }
198
- else if ( os . Contains ( "bullseye" ) )
199
- {
200
- displayName = "Debian 11" ;
201
- }
202
- else if ( os . Contains ( "bookworm" ) )
203
- {
204
- displayName = "Debian 12" ;
205
- }
206
- else if ( os . Contains ( "xenial" ) )
207
- {
208
- displayName = "Ubuntu 16.04" ;
209
- }
210
- else if ( os . Contains ( "bionic" ) )
211
- {
212
- displayName = "Ubuntu 18.04" ;
213
- }
214
- else if ( os . Contains ( "disco" ) )
215
- {
216
- displayName = "Ubuntu 19.04" ;
217
- }
218
- else if ( os . Contains ( "focal" ) )
219
- {
220
- displayName = "Ubuntu 20.04" ;
221
- }
222
- else if ( os . Contains ( "hirsute" ) )
223
- {
224
- displayName = "Ubuntu 21.04" ;
225
- }
226
- else if ( os . Contains ( "impish" ) )
227
- {
228
- displayName = "Ubuntu 21.10" ;
229
- }
230
- else if ( os . Contains ( "jammy" ) )
231
- {
232
- displayName = "Ubuntu 22.04" ;
233
- }
234
- else if ( os . Contains ( "noble" ) )
235
- {
236
- displayName = "Ubuntu 24.04" ;
237
- }
238
- else if ( os . Contains ( "alpine" ) || os . Contains ( "centos" ) || os . Contains ( "fedora" ) )
239
- {
240
- displayName = FormatVersionableOsName ( os , name => name . FirstCharToUpper ( ) ) ;
241
- }
242
- else if ( os . Contains ( "azurelinux" ) )
243
- {
244
- displayName = FormatVersionableOsName ( os , name => "Azure Linux" ) ;
245
- }
246
- else if ( os . Contains ( "cbl-mariner" ) )
247
- {
248
- displayName = FormatVersionableOsName ( os , name => "CBL-Mariner" ) ;
249
- }
250
- else if ( os . Contains ( "leap" ) )
251
- {
252
- displayName = FormatVersionableOsName ( os , name => "openSUSE Leap" ) ;
253
- }
254
- else if ( os . Contains ( "ubuntu" ) )
255
- {
256
- displayName = FormatVersionableOsName ( os , name => "Ubuntu" ) ;
257
- }
258
- else
259
- {
260
- throw new NotSupportedException ( $ "The OS version '{ os } ' is not supported.") ;
261
- }
262
- }
263
-
264
- return displayName ;
170
+ var s when s . StartsWith ( "nanoserver" ) => GetWindowsVersionDisplayName ( "Nano Server" , version ) ,
171
+ var s when s . StartsWith ( "windowsservercore" ) => GetWindowsVersionDisplayName ( "Windows Server Core" , version ) ,
172
+ _ => throw new NotSupportedException ( $ "The OS version '{ os } ' is not supported.")
173
+ } ;
265
174
}
266
175
267
- private static string GetWindowsVersionDisplayName ( string windowsName , string version )
176
+ private static string GetLinuxOSDisplayName ( string os )
268
177
{
269
- if ( version . StartsWith ( "ltsc" ) )
270
- {
271
- return $ "{ windowsName } { version . TrimStartString ( "ltsc" ) } ";
272
- }
273
- else
178
+ return os switch
274
179
{
275
- return $ "{ windowsName } , version { version } ";
276
- }
180
+ string s when s . Contains ( "debian" ) => "Debian" ,
181
+ string s when s . Contains ( "bookworm" ) => "Debian 12" ,
182
+ string s when s . Contains ( "trixie" ) => "Debian 13" ,
183
+ string s when s . Contains ( "forky" ) => "Debian 14" ,
184
+ string s when s . Contains ( "duke" ) => "Debian 15" ,
185
+ string s when s . Contains ( "jammy" ) => "Ubuntu 22.04" ,
186
+ string s when s . Contains ( "noble" ) => "Ubuntu 24.04" ,
187
+ string s when s . Contains ( "azurelinux" ) =>
188
+ FormatVersionableOsName ( os , name => "Azure Linux" ) ,
189
+ string s when s . Contains ( "cbl-mariner" ) =>
190
+ FormatVersionableOsName ( os , name => "CBL-Mariner" ) ,
191
+ string s when s . Contains ( "leap" ) =>
192
+ FormatVersionableOsName ( os , name => "openSUSE Leap" ) ,
193
+ string s when s . Contains ( "ubuntu" ) =>
194
+ FormatVersionableOsName ( os , name => "Ubuntu" ) ,
195
+ string s when s . Contains ( "alpine" )
196
+ || s . Contains ( "centos" )
197
+ || s . Contains ( "fedora" ) =>
198
+ FormatVersionableOsName ( os , name => name . FirstCharToUpper ( ) ) ,
199
+ _ => throw new NotSupportedException ( $ "The OS version '{ os } ' is not supported.")
200
+ } ;
277
201
}
278
202
203
+ private static string GetWindowsVersionDisplayName ( string windowsName , string version ) =>
204
+ version . StartsWith ( "ltsc" ) switch
205
+ {
206
+ true => $ "{ windowsName } { version . TrimStartString ( "ltsc" ) } ",
207
+ false => $ "{ windowsName } , version { version } "
208
+ } ;
209
+
279
210
public static bool AreMatchingPlatforms ( ImageInfo image1 , PlatformInfo platform1 , ImageInfo image2 , PlatformInfo platform2 ) =>
280
211
platform1 . GetUniqueKey ( image1 ) == platform2 . GetUniqueKey ( image2 ) ;
281
212
0 commit comments