@@ -27,29 +27,59 @@ public static class Program
27
27
{
28
28
private const string Validate = "-v" ;
29
29
private const string Create = "-c" ;
30
+ private const string UpdateVersion = "-u" ;
30
31
31
32
private static readonly Dictionary < string , Action < string > > ModeMap = new Dictionary < string , Action < string > >
32
33
{
33
34
{ Validate , ValidateDefinitionFiles } ,
34
- { Create , CreateDefinitionFiles }
35
+ { Create , CreateDefinitionFiles } ,
36
+ { UpdateVersion , p => UpdateModuleVersions ( p , _newVersion ) }
35
37
} ;
38
+
39
+ private static Version _newVersion ;
40
+
36
41
public static void Main ( string [ ] args )
37
42
{
38
- var rmPath = args . FirstOrDefault ( a => ! ModeMap . ContainsKey ( a ) ) ?? @"..\..\..\src\ResourceManager" ;
43
+ var rmPath = args . FirstOrDefault ( a => ! ModeMap . ContainsKey ( a . ToLower ( ) ) ) ?? @"..\..\..\src\ResourceManager" ;
39
44
if ( ! Directory . Exists ( rmPath ) )
40
45
{
41
46
throw new ArgumentException ( $ "Directory [{ rmPath } ] does not exist") ;
42
47
}
43
48
//https://stackoverflow.com/a/17563994/294804
44
- var mode = args . Any ( a => a . IndexOf ( Create , StringComparison . InvariantCultureIgnoreCase ) >= 0 ) ? Create : Validate ;
49
+ var mode = ModeMap . Keys . FirstOrDefault ( k => args . Any ( a => a . IndexOf ( k , StringComparison . InvariantCultureIgnoreCase ) >= 0 ) ) ?? Validate ;
50
+ if ( mode == UpdateVersion )
51
+ {
52
+ var newVersion = args . FirstOrDefault ( a => Version . TryParse ( a , out var _ ) ) ;
53
+ _newVersion = Version . Parse ( newVersion ?? "0.12.0" ) ;
54
+ }
45
55
ModeMap [ mode ] ( rmPath ) ;
46
56
}
47
57
58
+ private static void UpdateModuleVersions ( string rmPath , Version newVersion )
59
+ {
60
+ var modulePaths = GetModulePaths ( rmPath , true ) ;
61
+ var desktopFilePaths = GetDesktopFilePaths ( modulePaths ) ;
62
+ var netCoreFilePaths = desktopFilePaths . Select ( ConvertDesktopToNetCorePath ) . Where ( File . Exists ) . ToList ( ) ;
63
+ netCoreFilePaths . Add ( Path . Combine ( rmPath , @"..\Storage\Azure.Storage.Netcore.psd1" ) ) ;
64
+ var netCoreHashTables = GetHashtables ( netCoreFilePaths ) ;
65
+
66
+ foreach ( var netCoreHashtable in netCoreHashTables )
67
+ {
68
+ var netCoreDefinition = CreateNetCoreDefinition ( netCoreHashtable ) ;
69
+ netCoreDefinition . ModuleVersion = newVersion ;
70
+ if ( netCoreDefinition . RequiredModules . Any ( rm => rm . ModuleName == "AzureRM.Profile.Netcore" ) )
71
+ {
72
+ netCoreDefinition . RequiredModules . First ( rm => rm . ModuleName == "AzureRM.Profile.Netcore" ) . ModuleVersion = newVersion ;
73
+ }
74
+ File . WriteAllLines ( netCoreHashtable . GetValueAsString ( "FilePath" ) , netCoreDefinition . ToDefinitionEntry ( ) ) ;
75
+ }
76
+ }
77
+
48
78
private static void ValidateDefinitionFiles ( string rmPath )
49
79
{
50
80
var modulePaths = GetModulePaths ( rmPath , true ) ;
51
81
var desktopFilePaths = GetDesktopFilePaths ( modulePaths ) ;
52
- var desktopHashtables = GetDesktopHashtables ( desktopFilePaths ) ;
82
+ var desktopHashtables = GetHashtables ( desktopFilePaths ) ;
53
83
foreach ( var desktopHashtable in desktopHashtables )
54
84
{
55
85
var netCorePath = ConvertDesktopToNetCorePath ( desktopHashtable . GetValueAsString ( "FilePath" ) ) ;
@@ -109,7 +139,7 @@ private static void CreateDefinitionFiles(string rmPath)
109
139
{
110
140
var modulePaths = GetModulePaths ( rmPath ) ;
111
141
var desktopFilePaths = GetDesktopFilePaths ( modulePaths ) ;
112
- var desktopHashtables = GetDesktopHashtables ( desktopFilePaths ) ;
142
+ var desktopHashtables = GetHashtables ( desktopFilePaths ) ;
113
143
foreach ( var desktopHashtable in desktopHashtables )
114
144
{
115
145
var netCoreFilePath = ConvertDesktopToNetCorePath ( desktopHashtable . GetValueAsString ( "FilePath" ) ) ;
0 commit comments