@@ -124,36 +124,29 @@ class FunctionConfig {
124
124
port = defaults? .port ?? defaultPort;
125
125
}
126
126
127
+ final functionTypeOptionValue = options[_functionTypeOpt] as String ;
128
+
127
129
return FunctionConfig (
128
130
port: port,
129
131
target: options[_targetOpt] as String ??
130
132
defaults? .target ??
131
133
defaultFunctionTarget,
132
- functionType: _parseFunctionType (options[_functionTypeOpt] as String ) ??
133
- defaults? .functionType ??
134
- defaultFunctionType ,
134
+ functionType: functionTypeOptionValue == null
135
+ ? defaults? .functionType ?? defaultFunctionType
136
+ : _parseFunctionType (functionTypeOptionValue) ,
135
137
);
136
138
}
137
139
}
138
140
139
- FunctionType _parseFunctionType (String type) {
140
- type ?? = '' ;
141
- switch (type) {
142
- case '' :
143
- return defaultFunctionType;
144
- case 'http' :
145
- return FunctionType .http;
146
- case 'cloudevent' :
147
- return FunctionType .cloudevent;
148
- default :
149
- throw BadConfigurationException (
141
+ FunctionType _parseFunctionType (String type) => FunctionType .values.singleWhere (
142
+ (element) => type == _enumValue (element),
143
+ orElse: () => throw BadConfigurationException (
150
144
'FUNCTION_SIGNATURE_TYPE environment variable "$type " is not a valid '
151
145
'option (must be "http" or "cloudevent")' ,
152
- );
153
- }
154
- }
146
+ ),
147
+ );
155
148
156
- String _enumValue (Object enumEntry) {
149
+ String _enumValue (FunctionType enumEntry) {
157
150
final v = enumEntry.toString ();
158
151
return v.substring (v.indexOf ('.' ) + 1 );
159
152
}
0 commit comments