static async Task Main(string[] args) { var result = Parser.Default .ParseArguments <DownloadCommand, InstallCommand, ListCommand, NewCommand>(args); await result.MapResult ( async (DownloadCommand downloadCommand) => await DownloadParser.Parse(downloadCommand), async (InstallCommand installCommand) => await InstallParser.Parse(installCommand), async (ListCommand listCommand) => await Task.Run(() => ListParser.Parse()), async (NewCommand newCommand) => await NewParser.Parser(), async error => await Task.FromResult(1) ); }
public static int Parse() { if (_parser == null) { _parser = new ListParser(); } try { Console.WriteLine(_parser.List()); return(0); } catch (Exception e) { Console.WriteLine("解析错误,错误信息:{0}", e.Message); return(1); } }