A Configgy extension that allows command line parsing via CommandLineParser
First setup Configgy like in the documentation.
Create a command line options class like so: (See here)
class Options {
[Option('t', "text", HelpText="Input text")]
public string Text { get; set; }
}Now add the new source to your Config subclass by overwriting the default constructor:
public class MyConfig: Config, IMyConfig
{
public int MaxThingCount { get { return Get<int>(); } }
public string DatabaseConectionString { get { return Get<string>(); } }
public DateTime WhenToShutdown { get { return Get<DateTime>(); } }
public MyConfig(string[] arguments)
: base(
new DictionaryCache(),
new AggregateSource(
new CommandLineParserSource<Options>(arguments),
new EnvironmentVariableSource(),
new FileSource(),
new ConnectionStringsSource(),
new AppSettingSource(),
new EmbeddedResourceSource(),
new DefaultValueAttributeSource()
),
new AggregateTransformer(),
new AggregateValidator(),
new AggregateCoercer()
)
{
}
}This simply reproduces the normal default constructor but adds a CommandLineParserSource as one of the sources using the Options type we've already defined and gives it the arguments to parse.
You can build from this source or you can get it from nuget here: https://www.nuget.org/packages/Configgy.CommandLineParser