Show proper error message if using incompatible options

This commit is contained in:
nicolas.dorier
2019-11-12 13:43:23 +09:00
parent 3c64f6618d
commit 5d031d9638
2 changed files with 17 additions and 2 deletions

View File

@@ -54,6 +54,7 @@ namespace DockerGenerator
var volumes = new List<KeyValuePair<YamlNode, YamlNode>>();
var networks = new List<KeyValuePair<YamlNode, YamlNode>>();
var exclusives = new List<(FragmentName FragmentName, string Exclusivity)>();
var incompatibles = new List<(FragmentName FragmentName, string Exclusivity)>();
foreach (var fragment in Fragments.Where(NotExcluded))
{
@@ -92,6 +93,13 @@ namespace DockerGenerator
exclusives.Add((fragment, node.ToString()));
}
}
if (doc.Children.ContainsKey("incompatible") && doc.Children["incompatible"] is YamlSequenceNode fragmentIncompatibleRoot)
{
foreach (var node in fragmentIncompatibleRoot)
{
incompatibles.Add((fragment, node.ToString()));
}
}
if (doc.Children.ContainsKey("required") && doc.Children["required"] is YamlSequenceNode fragmentRequireRoot)
{
foreach (var node in fragmentRequireRoot)
@@ -126,6 +134,14 @@ namespace DockerGenerator
if (exclusiveConflict != null)
throw new YamlBuildException($"The fragments {String.Join(", ", exclusiveConflict.Select(e => e.FragmentName))} can't be used simultaneously (group '{exclusiveConflict.Key}')");
var groups = exclusives.ToDictionary(e => e.Exclusivity, e => e.FragmentName);
var incompatible = incompatibles
.Select(i => groups.TryGetValue(i.Exclusivity, out _) ? (i.FragmentName, i.Exclusivity) : (null, null))
.Where(i => i.Exclusivity != null)
.FirstOrDefault();
if (incompatible.Exclusivity != null)
throw new YamlBuildException($"The fragment {incompatible.FragmentName} is incompatible with '{incompatible.Exclusivity}'");
Console.WriteLine($"Selected fragments:");
foreach (var fragment in processedFragments)
{

View File

@@ -11,8 +11,7 @@
"BTCPAYGEN_CRYPTO2": "ltc",
"BTCPAYGEN_CRYPTO1": "btc",
"BTCPAYGEN_REVERSEPROXY": "nginx",
"BTCPAYGEN_ADDITIONAL_FRAGMENTS": "opt-save-storage",
"BTCPAYGEN_EXCLUDE_FRAGMENTS": "postgres"
"BTCPAYGEN_ADDITIONAL_FRAGMENTS": "opt-save-storage;opt-txindex"
}
}
}