diff --git a/src/Tools/RepoUtil/RepoData.json b/build/config/RepoUtilData.json similarity index 100% rename from src/Tools/RepoUtil/RepoData.json rename to build/config/RepoUtilData.json diff --git a/src/Tools/RepoUtil/Program.cs b/src/Tools/RepoUtil/Program.cs index 6d464e7125912718ef454356a8a72a8200744986..9725e74adeee75534bc4e8f36b402d9267147140 100644 --- a/src/Tools/RepoUtil/Program.cs +++ b/src/Tools/RepoUtil/Program.cs @@ -12,7 +12,7 @@ internal static class Program { private sealed class ParsedArgs { - internal string RepoDataPath { get; set; } + internal string RepoUtilDataPath { get; set; } internal string SourcesPath { get; set; } internal string[] RemainingArgs { get; set; } } @@ -25,7 +25,9 @@ internal static int Main(string[] args) try { if (Run(args)) + { result = 0; + } } catch (ConflictingPackagesException ex) { @@ -55,9 +57,17 @@ private static bool Run(string[] args) return false; } - var repoConfig = RepoConfig.ReadFrom(parsedArgs.RepoDataPath); + var repoConfig = RepoConfig.ReadFrom(parsedArgs.RepoUtilDataPath); var command = func(repoConfig, parsedArgs.SourcesPath); - return command.Run(Console.Out, parsedArgs.RemainingArgs); + if (command.Run(Console.Out, parsedArgs.RemainingArgs)) + { + return true; + } + else + { + Console.WriteLine($"RepoUtil config read from: {parsedArgs.RepoUtilDataPath}"); + return false; + } } private static bool TryParseCommandLine(string[] args, out ParsedArgs parsedArgs, out CreateCommand func) @@ -67,8 +77,6 @@ private static bool TryParseCommandLine(string[] args, out ParsedArgs parsedArgs // Setup the default values var binariesPath = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(AppContext.BaseDirectory)))); - parsedArgs.SourcesPath = Path.GetDirectoryName(binariesPath); - parsedArgs.RepoDataPath = Path.Combine(AppContext.BaseDirectory, "RepoData.json"); var index = 0; if (!TryParseCommon(args, ref index, parsedArgs)) @@ -81,12 +89,24 @@ private static bool TryParseCommandLine(string[] args, out ParsedArgs parsedArgs return false; } + parsedArgs.SourcesPath = parsedArgs.SourcesPath ?? GetDirectoryName(AppContext.BaseDirectory, 5); + parsedArgs.RepoUtilDataPath = parsedArgs.RepoUtilDataPath ?? Path.Combine(parsedArgs.SourcesPath, @"build\config\RepoUtilData.json"); parsedArgs.RemainingArgs = index >= args.Length ? Array.Empty() : args.Skip(index).ToArray(); return true; } + private static string GetDirectoryName(string path, int depth) + { + for (var i = 0; i < depth; i++) + { + path = Path.GetDirectoryName(path); + } + + return path; + } + private static bool TryParseCommon(string[] args, ref int index, ParsedArgs parsedArgs) { while (index < args.Length) @@ -114,6 +134,20 @@ private static bool TryParseCommon(string[] args, ref int index, ParsedArgs pars } break; } + case "-config": + { + if (index < args.Length) + { + parsedArgs.RepoUtilDataPath = args[index]; + index++; + } + else + { + Console.WriteLine($"The -config switch needs a value"); + return false; + } + break; + } default: Console.Write($"Option {arg} is unrecognized"); return false; diff --git a/src/Tools/RepoUtil/RepoUtil.csproj b/src/Tools/RepoUtil/RepoUtil.csproj index e11d49fae6da956c8726d5dce2b7d0616ccc391a..cb922a2332e43690f9c1089d4ec5afb75cf695b5 100644 --- a/src/Tools/RepoUtil/RepoUtil.csproj +++ b/src/Tools/RepoUtil/RepoUtil.csproj @@ -63,9 +63,6 @@ - - PreserveNewest -