private static IEnumerable <IEnumerable <OptionSource> > GetConfig <TOptions>(string[] args, string environmentPrefix, string defaultConfigLocation = null) where TOptions : class, IOptions, new() { var commandline = CommandLine.Parse <TOptions>(args).Normalize(); var commanddict = commandline.ToDictionary(x => x.Name.ToLower()); yield return(commandline); yield return(EnvironmentVariables.Parse <TOptions>(x => NameTranslators.PrefixEnvironmentVariable(x, environmentPrefix).ToUpper())); var configFile = commanddict.ContainsKey("config") ? commanddict["config"].Value as string : null; if (configFile == null && File.Exists(defaultConfigLocation)) { configFile = defaultConfigLocation; yield return(new OptionSource[] { OptionSource.String("Config File", "config", defaultConfigLocation) }); } if (configFile != null) { if (!File.Exists(configFile)) { throw new OptionException(String.Format("The specified config file {0} could not be found", configFile), "config"); } yield return(Yaml.FromFile(configFile)); } yield return(TypeDefaultOptions.Get <TOptions>()); }
private static IEnumerable <IEnumerable <OptionSource> > GetConfig(string[] args) { var commandline = CommandLine.Parse <SomeOptionType>(args).Normalize(); var commanddict = commandline.ToDictionary(x => x.Name); yield return(commandline); yield return (EnvironmentVariables.Parse <SomeOptionType>(x => NameTranslators.PrefixEnvironmentVariable(x, "EVENTSTORE"))); var configFile = commanddict.ContainsKey("config") ? commanddict["config"].Value as string : null; if (configFile != null && File.Exists(configFile)) { yield return (Yaml.FromFile(configFile)); } yield return (TypeDefaultOptions.Get <SomeOptionType>()); yield return (MyOwnCustomDefaultsAintThatNeat()); }