6
6
* available at https://raw.githubusercontent.com/FirelyTeam/firely-cql-sdk/main/LICENSE
7
7
*/
8
8
9
+ using System . Collections ;
9
10
using Hl7 . Cql . Packager ;
10
11
using Hl7 . Cql . Packager . Commands . Logging ;
11
12
using Hl7 . Cql . Packager . Options ;
@@ -17,6 +18,8 @@ namespace Microsoft.Extensions.DependencyInjection;
17
18
18
19
internal static class PackagerCliServiceCollectionExtensions
19
20
{
21
+ public const string ? EnvironmentVariablePrefix = "CQLPACKAGE" ;
22
+
20
23
public static IServiceCollection AddPackagerCliOptions (
21
24
this IServiceCollection services ) =>
22
25
services . AddAndBindOptions < CqlOptions > ( )
@@ -26,6 +29,7 @@ public static IServiceCollection AddPackagerCliOptions(
26
29
27
30
public static IConfigurationBuilder AddPackagerCliAppSettings (
28
31
this IConfigurationBuilder config ,
32
+ string profile ,
29
33
Func < IEnumerable < ( object ? value , string [ ] sectionPath ) > > ? additionalConfiguration = null )
30
34
{
31
35
var buildConfiguration = typeof ( Program ) . Assembly . GetCustomAttribute < AssemblyConfigurationAttribute > ( ) ? . Configuration ? . ToLowerInvariant ( ) ;
@@ -36,15 +40,24 @@ public static IConfigurationBuilder AddPackagerCliAppSettings(
36
40
var asmDirName = asmFileInfo . DirectoryName ! ;
37
41
var asmFileNameNoExt = asmFileInfo . Name [ ..^ 4 ] ; // Trim ".dll"
38
42
39
- config . AddEnvironmentVariables ( "CQLPACKAGE" ) ;
43
+ config . AddEnvironmentVariables ( EnvironmentVariablePrefix ) ;
40
44
41
45
IEnumerable < string > files =
42
46
[
43
47
Path . Combine ( asmDirName , $ "{ asmFileNameNoExt } .appsettings.json") ,
44
48
Path . Combine ( curDirName , $ "{ asmFileNameNoExt } .appsettings.json") ,
45
49
Path . Combine ( asmDirName , $ "{ asmFileNameNoExt } .appsettings.{ buildConfiguration } .json") ,
46
- Path . Combine ( curDirName , $ "{ asmFileNameNoExt } .appsettings.{ buildConfiguration } .json")
50
+ Path . Combine ( curDirName , $ "{ asmFileNameNoExt } .appsettings.{ buildConfiguration } .json") ,
47
51
] ;
52
+
53
+ if ( profile . Trim ( ) is { Length : > 0 } p )
54
+ {
55
+ files = files . Concat (
56
+ [
57
+ Path . Combine ( asmDirName , $ "{ asmFileNameNoExt } .{ p } .appsettings.json") ,
58
+ Path . Combine ( curDirName , $ "{ asmFileNameNoExt } .{ p } .appsettings.json")
59
+ ] ) ;
60
+ }
48
61
files = files . Distinct ( ) ;
49
62
foreach ( var file in files )
50
63
config . AddJsonFile ( file , optional : true , reloadOnChange : false ) ;
@@ -54,7 +67,7 @@ public static IConfigurationBuilder AddPackagerCliAppSettings(
54
67
? . Invoke ( )
55
68
. Where ( ad => ad . value is not null )
56
69
. Select ( KeyValuePair ! )
57
- . ToArray ( ) is { } additionalData )
70
+ . ToArray ( ) is { Length : >= 0 } additionalData )
58
71
config . Sources . Add ( new MemoryConfigurationSource { InitialData = additionalData } ) ;
59
72
60
73
return config ;
0 commit comments