Abstracted out command arguments a bit
This commit is contained in:
20
NadekoBot.Core/Common/OptionsParser.cs
Normal file
20
NadekoBot.Core/Common/OptionsParser.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using CommandLine;
|
||||
|
||||
namespace NadekoBot.Core.Common
|
||||
{
|
||||
public class OptionsParser
|
||||
{
|
||||
private static OptionsParser _instance = new OptionsParser();
|
||||
public static OptionsParser Default => _instance;
|
||||
|
||||
static OptionsParser() { }
|
||||
|
||||
public T ParseFrom<T>(T options, string[] args) where T : INadekoCommandOptions
|
||||
{
|
||||
var res = Parser.Default.ParseArguments<T>(args);
|
||||
options = (T)res.MapResult(x => x, x => options);
|
||||
options.NormalizeOptions();
|
||||
return options;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user