public static void DefaultParsingErrorsHandler(CommandLineOptionsBase options, HelpText current) { if (options == null) throw new ArgumentNullException("options"); if (current == null) throw new ArgumentNullException("current"); if (options.InternalLastPostParsingState.Errors.Count <= 0) return; var errors = current.RenderParsingErrorsText(options, 2); // indent with two spaces if (string.IsNullOrWhiteSpace(errors)) return; current.AddPreOptionsLine(string.Concat(Environment.NewLine, current.SentenceBuilder.ErrorsHeadingText)); var lines = errors.Split(new[] { Environment.NewLine }, StringSplitOptions.None); foreach (var line in lines) { current.AddPreOptionsLine(line); } }
/// <summary> /// Creates a new instance of the <see cref="HelpText"/> class using common defaults. /// </summary> /// <returns> /// An instance of <see cref="HelpText"/> class. /// </returns> /// <param name='options'> /// The instance that collected command line arguments parsed with <see cref="CommandLineParser"/> class. /// </param> /// <param name='err'> /// A delegate used to customize the text block for reporting parsing errors. /// </param> public static HelpText AutoBuild(object options, HandleParsingErrors err) { var title = ReflectionUtil.GetAttribute<AssemblyTitleAttribute>(); if (title == null) throw new InvalidOperationException("HelpText::AutoBuild() requires that you define AssemblyTitleAttribute."); var version = ReflectionUtil.GetAttribute<AssemblyInformationalVersionAttribute>(); if (version == null) throw new InvalidOperationException("HelpText::AutoBuild() requires that you define AssemblyInformationalVersionAttribute."); var copyright = ReflectionUtil.GetAttribute<AssemblyCopyrightAttribute>(); if (copyright == null) throw new InvalidOperationException("HelpText::AutoBuild() requires that you define AssemblyCopyrightAttribute."); var auto = new HelpText { Heading = new HeadingInfo(Path.GetFileNameWithoutExtension(title.Title), version.InformationalVersion), AdditionalNewLineAfterOption = true, AddDashesToOption = true }; if (err != null) { var typedTarget = options as CommandLineOptionsBase; if (typedTarget != null) { err(auto); } } auto.AddOptions(options); return auto; }