private string ConvertError(ParserResult <object> result) { return(new JObject(new JProperty("error", GetHelpText())).ToString()); string GetHelpText() { IEnumerable <Error> errors = ((NotParsed <object>)result).Errors.ToArray(); if (errors.Any(e => e.Tag == ErrorType.VersionRequestedError)) { return(new HelpText(CreateHeadingInfo()) { MaximumDisplayWidth = DisplayWidth }.AddPreOptionsLine(Environment.NewLine).ToString()); } ParserTypeInfo typeInfo = result.GetTypeInfo(); if (typeInfo == null) { return("Could not construct help because command was not parsed as expected."); } bool helpRequested = errors.Any(e => e.Tag == ErrorType.HelpVerbRequestedError) || errors.Any(e => e.Tag == ErrorType.HelpRequestedError); string help = ConstructHelp(result, typeInfo); return(help); } }
private Task <int> OnError(ParserResult <object> result) { IEnumerable <Error> errors = ((NotParsed <object>)result).Errors.ToArray(); if (errors.Any(e => e.Tag == ErrorType.VersionRequestedError)) { userInterface.WriteInformation(new HelpText(CreateHeadingInfo()) { MaximumDisplayWidth = DisplayWidth }.AddPreOptionsLine(Environment.NewLine)); return(Task.FromResult(0)); } ParserTypeInfo typeInfo = result.GetTypeInfo(); if (typeInfo == null) { userInterface.WriteError("Could not construct help because command was not parsed as expected."); return(Task.FromResult(1)); } bool helpRequested = errors.Any(e => e.Tag == ErrorType.HelpVerbRequestedError) || errors.Any(e => e.Tag == ErrorType.HelpRequestedError); string help = ConstructHelp(result, typeInfo); userInterface.WriteInformation(help); return(Task.FromResult(helpRequested ? 0 : 1)); }