public static bool RequiredOption(ArgumentsDictionary commandOptions, string name, out string value) { if (!commandOptions.TryGetValue(name.ToLowerInvariant(), out value)) { Console.WriteLine($"Missing required option: --{name}"); return(false); } return(true); }
public static string BuildUnitFile(ConfigurationOption[] options, ArgumentsDictionary optionValues, Dictionary <string, string> substitutions) { var sb = new StringBuilder(); string currentSection = null; foreach (var option in options) { IReadOnlyCollection <string> value; if (!optionValues.TryGetValue(option.Name.ToLowerInvariant(), out value)) { string defaultValue = option.Default; if (defaultValue != null) { value = new[] { defaultValue }; } } if (value != null && value.Count > 0 && !string.IsNullOrEmpty(value.First())) { // Start a new section if (currentSection != option.Section) { if (currentSection != null) { sb.AppendLine(); } sb.AppendLine($"[{option.Section}]"); currentSection = option.Section; } foreach (var val in value) { string substitutedValue = val; foreach (var subsitution in substitutions) { substitutedValue = substitutedValue.Replace(subsitution.Key, subsitution.Value); } sb.AppendLine($"{option.Name}={substitutedValue}"); } } } return(sb.ToString()); }