@@ -27,11 +27,11 @@ public class YamlFrontMatter
2727
2828
2929 [ YamlMember ( Alias = "applies" ) ]
30- public DeploymentType ? AppliesTo { get ; set ; }
30+ public Deployment ? AppliesTo { get ; set ; }
3131}
3232
3333[ YamlSerializable ]
34- public class DeploymentType
34+ public class Deployment
3535{
3636 [ YamlMember ( Alias = "self" ) ]
3737 public SelfManagedDeployment ? SelfManaged { get ; set ; }
@@ -40,6 +40,11 @@ public class DeploymentType
4040 public CloudManagedDeployment ? Cloud { get ; set ; }
4141}
4242
43+ public class AllVersions ( ) : SemVersion ( 9999 , 9999 , 9999 )
44+ {
45+ public static AllVersions Instance { get ; } = new ( ) ;
46+ }
47+
4348[ YamlSerializable ]
4449public class SelfManagedDeployment
4550{
@@ -51,6 +56,13 @@ public class SelfManagedDeployment
5156
5257 [ YamlMember ( Alias = "eck" ) ]
5358 public SemVersion ? Eck { get ; set ; }
59+
60+ public static SelfManagedDeployment All { get ; } = new ( )
61+ {
62+ Stack = AllVersions . Instance ,
63+ Ece = AllVersions . Instance ,
64+ Eck = AllVersions . Instance
65+ } ;
5466}
5567
5668[ YamlSerializable ]
@@ -61,6 +73,13 @@ public class CloudManagedDeployment
6173
6274 [ YamlMember ( Alias = "serverless" ) ]
6375 public SemVersion ? Serverless { get ; set ; }
76+
77+ public static CloudManagedDeployment All { get ; } = new ( )
78+ {
79+ Ess = AllVersions . Instance ,
80+ Serverless = AllVersions . Instance
81+ } ;
82+
6483}
6584
6685public static class FrontMatterParser
@@ -72,6 +91,8 @@ public static YamlFrontMatter Deserialize(string yaml)
7291 var deserializer = new StaticDeserializerBuilder ( new YamlFrontMatterStaticContext ( ) )
7392 . IgnoreUnmatchedProperties ( )
7493 . WithTypeConverter ( new SemVersionConverter ( ) )
94+ . WithTypeConverter ( new CloudManagedSerializer ( ) )
95+ . WithTypeConverter ( new SelfManagedSerializer ( ) )
7596 . Build ( ) ;
7697
7798 var frontMatter = deserializer . Deserialize < YamlFrontMatter > ( input ) ;
@@ -87,6 +108,10 @@ public class SemVersionConverter : IYamlTypeConverter
87108 public object ? ReadYaml ( IParser parser , Type type , ObjectDeserializer rootDeserializer )
88109 {
89110 var value = parser . Consume < Scalar > ( ) ;
111+ if ( string . IsNullOrWhiteSpace ( value . Value ) )
112+ return AllVersions . Instance ;
113+ if ( string . Equals ( value . Value , "all" , StringComparison . InvariantCultureIgnoreCase ) )
114+ return AllVersions . Instance ;
90115 return ( SemVersion ) value . Value ;
91116 }
92117
@@ -97,3 +122,65 @@ public void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializ
97122 emitter . Emit ( new Scalar ( value . ToString ( ) ! ) ) ;
98123 }
99124}
125+
126+ public class CloudManagedSerializer : IYamlTypeConverter
127+ {
128+ public bool Accepts ( Type type ) => type == typeof ( CloudManagedDeployment ) ;
129+
130+ public object ? ReadYaml ( IParser parser , Type type , ObjectDeserializer rootDeserializer )
131+ {
132+ if ( parser . TryConsume < Scalar > ( out var value ) )
133+ {
134+ if ( string . IsNullOrWhiteSpace ( value . Value ) )
135+ return CloudManagedDeployment . All ;
136+ if ( string . Equals ( value . Value , "all" , StringComparison . InvariantCultureIgnoreCase ) )
137+ return CloudManagedDeployment . All ;
138+ }
139+ var x = rootDeserializer . Invoke ( typeof ( Dictionary < string , string > ) ) ;
140+ if ( x is not Dictionary < string , string > { Count : > 0 } dictionary )
141+ return null ;
142+
143+ var cloudManaged = new CloudManagedDeployment ( ) ;
144+ if ( dictionary . TryGetValue ( "ess" , out var v ) )
145+ cloudManaged . Ess = ( SemVersion ) v ;
146+ if ( dictionary . TryGetValue ( "serverless" , out v ) )
147+ cloudManaged . Serverless = ( SemVersion ) v ;
148+ return cloudManaged ;
149+
150+ }
151+
152+ public void WriteYaml ( IEmitter emitter , object ? value , Type type , ObjectSerializer serializer ) =>
153+ serializer . Invoke ( value , type ) ;
154+ }
155+
156+ public class SelfManagedSerializer : IYamlTypeConverter
157+ {
158+ public bool Accepts ( Type type ) => type == typeof ( SelfManagedDeployment ) ;
159+
160+ public object ? ReadYaml ( IParser parser , Type type , ObjectDeserializer rootDeserializer )
161+ {
162+ if ( parser . TryConsume < Scalar > ( out var value ) )
163+ {
164+ if ( string . IsNullOrWhiteSpace ( value . Value ) )
165+ return SelfManagedDeployment . All ;
166+ if ( string . Equals ( value . Value , "all" , StringComparison . InvariantCultureIgnoreCase ) )
167+ return SelfManagedDeployment . All ;
168+ }
169+ var x = rootDeserializer . Invoke ( typeof ( Dictionary < string , string > ) ) ;
170+ if ( x is not Dictionary < string , string > { Count : > 0 } dictionary )
171+ return null ;
172+
173+ var deployment = new SelfManagedDeployment ( ) ;
174+ if ( dictionary . TryGetValue ( "stack" , out var v ) )
175+ deployment . Stack = ( SemVersion ) v ;
176+ if ( dictionary . TryGetValue ( "ece" , out v ) )
177+ deployment . Ece = ( SemVersion ) v ;
178+ if ( dictionary . TryGetValue ( "eck" , out v ) )
179+ deployment . Eck = ( SemVersion ) v ;
180+ return deployment ;
181+
182+ }
183+
184+ public void WriteYaml ( IEmitter emitter , object ? value , Type type , ObjectSerializer serializer ) =>
185+ serializer . Invoke ( value , type ) ;
186+ }
0 commit comments