Exemple #1
0
 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)
     );
 }
Exemple #2
0
        public static async Task <int> Parse(DownloadCommand command)
        {
            if (_parser == null)
            {
                _parser = new DownloadParser();
            }

            try
            {
                _parser.Options = command;
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine("模板参数有误,请检查后重试。错误信息:{0}", e.Message);
            }
            catch (ParseException e)
            {
                Console.WriteLine("模板参数有误,请检查后重试。错误信息:{0}", e.Message);
            }

            return(await _parser.Parse());
        }