public virtual Document HelpNotParsed(object errorsSource = null, HelpParts partsErrors = HelpParts.DefaultErrors, HelpParts partsOptions = HelpParts.DefaultOptions, HelpParts partsVersion = HelpParts.DefaultVersion) { if (errorsSource != null) { return(With(errorsSource: errorsSource).HelpNotParsed(null, partsErrors, partsOptions, partsVersion)); } if (!Info.Parts.Has(HelpParts.Errors)) { return(Help(HelpParts.None)); } if (Info.Errors.Any(e => e.Kind == ErrorKind.ParseError)) { return(Help(partsErrors)); } if (Info.Errors.Any(e => e.Kind == ErrorKind.VersionVerb)) { return(Help(partsVersion)); } if (Info.Errors.Any(e => e.Kind == ErrorKind.HelpVerb)) { var helpError = Info.Errors.First(e => e.Kind == ErrorKind.HelpVerb); if (helpError.TypeKey != null) { return(With(optionsSource: new[] { helpError.TypeKey }).Help((partsOptions | HelpParts.SubOptions) & ~HelpParts.BuiltInOptions)); } } return(Help(partsErrors)); }
private object GetAssemblyLicenseCore(HelpParts parts) { if (!parts.Has(HelpParts.AssemblyLicense)) { return(null); } return(GetAssemblyLicense(parts)); }
private object GetAssemblyTitleCore(HelpParts parts) { if (!parts.Has(HelpParts.AssemblyTitle | HelpParts.AssemblyVersion)) { return(null); } return(GetAssemblyTitle(parts)); }
private object GetUsageCore(HelpParts parts) { if (!parts.Has(HelpParts.AssemblyUsage)) { return(null); } return(GetUsage(parts)); }
private object GetExamplesCore(HelpParts parts) { if (!parts.Has(HelpParts.Examples) || !Info.Parts.Has(HelpParts.Examples) || !Info.Examples.SelectMany(e => e).Any()) { return(null); } return(GetExamples(parts)); }
private object GetErrorsCore(HelpParts parts) { if (!parts.Has(HelpParts.Errors) || !Info.Parts.Has(HelpParts.Errors) || Info.Errors.All(e => e.Message == null)) { return(null); } return(GetErrors(parts)); }
private object GetOptionsCore(HelpParts parts) { if (!parts.Has(HelpParts.Options) || !Info.Parts.Has(HelpParts.Options) || !Info.Options.Any(IsOptionVisible(parts))) { return(null); } return(GetOptions(parts)); }
private object GetAssemblyCopyrightCore(HelpParts parts) { if (!parts.Has(HelpParts.AssemblyCopyright)) { return(null); } return(GetAssemblyCopyright(parts)); }
protected virtual object GetAssemblyTitle(HelpParts parts) { string title = EffectiveAssembly?.GetCustomAttributes <AssemblyTitleAttribute>().FirstOrDefault()?.Title ?? EffectiveAssembly?.GetName().Name; string version = EffectiveAssembly?.GetCustomAttributes <AssemblyInformationalVersionAttribute>().FirstOrDefault()?.InformationalVersion ?? EffectiveAssembly?.GetName().Version.ToString(); string line = string.Join(" ", parts.Has(HelpParts.AssemblyTitle) ? title : null, parts.Has(HelpParts.AssemblyVersion) ? version : null).Trim(); return(new Div(line)); }
protected virtual object GetHeader(HelpParts parts) { return(new Div { Color = AssemblyMetaColor, Children = { GetAssemblyTitleCore(parts), GetAssemblyCopyrightCore(parts), GetAssemblyLicenseCore(parts), Header, } }); }
public virtual Document HelpVerb(string verb, bool all = false, HelpParts partsAll = HelpParts.All, HelpParts partsVerb = HelpParts.DefaultOptions) { if (all) { return(Help(partsAll)); } else if (verb != null && !Info.ChooseVerb(verb)) { return(Message(ErrorInfo.Error($"Verb {verb} not supported."), HelpParts.DefaultErrors)); } return(Help(HelpParts.DefaultOptions | (verb != null ? HelpParts.SubOptions : 0))); }
public virtual Document Help(HelpParts parts) { return(new Document { Color = Color, Background = Background, Language = new XmlLanguage(EffectiveCulture), Margin = Margin, Children = { GetHeader(parts), GetErrorsCore(parts), GetUsageCore(parts), GetOptionsCore(parts), GetExamplesCore(parts), GetFooter(parts), } }); }
protected virtual object GetAssemblyCopyright(HelpParts parts) { string copyright = EffectiveAssembly?.GetCustomAttributes <AssemblyCopyrightAttribute>().FirstOrDefault()?.Copyright; if (copyright == null) { string company = EffectiveAssembly?.GetCustomAttributes <AssemblyCompanyAttribute>().FirstOrDefault()?.Company; if (company == null) { return(null); } copyright = $"{company} © {DateTime.UtcNow.Year}"; } if (copyright.IndexOf("Copyright", StringComparison.OrdinalIgnoreCase) == -1) { copyright = $"Copyright {copyright}"; } return(new Div(copyright)); }
protected virtual object GetExamples(HelpParts parts) { return(new Div { Margin = SectionMargin, Children = { new Div(TitleTransform("Examples")) { Color = TitleColor }, new List { IndexFormat = new string('\n', ExampleGroupMargin.Top) + ListIndexFormat, Children = { Info.Examples.SelectMany(e => e).Select(GetExample) } } } }); }
protected virtual object GetSubOptions(OptionInfo option, HelpParts parts) { return(new Grid { Stroke = LineThickness.None, Columns = { new Column { Width = GridLength.Auto, MinWidth = OptionNameMinLength + SubOptionMargin.Left + 1, MaxWidth = OptionNameMaxLength + SubOptionMargin.Left + 1, }, new Column { Width = GridLength.Star(1) }, }, Children = { option.SubOptions.Where(IsOptionVisible(parts)).Select(o => GetOption(o, parts, isSubOption: true)) } }); }
protected virtual object GetOption(OptionInfo option, HelpParts parts, bool isSubOption) { var m = isSubOption ? SubOptionMargin : OptionMargin; var marginName = new Thickness(m.Left, m.Top, 1, m.Bottom); var marginText = new Thickness(0, m.Top, m.Right, m.Bottom); string values = parts.Has(HelpParts.OptionsValues) && option.HasHelpValues ? string.Join(", ", option.HelpValues) : null; string defaultValue = parts.Has(HelpParts.OptionsDefaultValue) && option.DefaultValue != null ? GetOptionDefault(option) : null; object subOptions = parts.Has(HelpParts.SubOptions) && option.SubOptions.Any(IsOptionVisible(parts)) ? GetSubOptions(option, parts) : null; return(new[] { new Div { Margin = marginName, Color = isSubOption ? SubOptionNameColor : OptionNameColor, TextWrap = TextWrap.WordWrapSpace, Children = { option.HelpNameWithValue } }, new Div { Margin = marginText, Color = OptionTextColor, Children = { option.HelpText, option.IsRequired ? " (Required)" : null, values != null ? $"\nValid values: {values}" : null, defaultValue != null ? $"\nDefault: {defaultValue}" : null } }, subOptions != null ? new Div { [Grid.ColumnSpanProperty] = 2, Children = { subOptions } } : null }); }
protected virtual object GetUsage(HelpParts parts) { string usage = ClpUtils.GetAssemblyUsageText(EffectiveAssembly); if (usage == "") { return(null); } return(new Div { Margin = SectionMargin, Children = { new Div(TitleTransform("Usage")) { Color = TitleColor }, new Div(usage) { Color = UsageTextColor }, } }); }
private Document Message(object errorsSource, HelpParts parts = HelpParts.Errors) => With(errorsSource: errorsSource).Help(parts);
protected virtual object GetErrors(HelpParts parts) { return(Info.Errors.Where(e => e.Message != null).Select(GetError)); }
public Document Message(ErrorInfo error, HelpParts parts = HelpParts.Errors) => Message((object)error, parts);
public Document Message(IEnumerable <ErrorInfo> errors, HelpParts parts = HelpParts.Errors) => Message((object)errors, parts);
protected virtual object GetFooter(HelpParts parts) { return(new Div(Footer)); }
protected virtual object GetAssemblyLicense(HelpParts parts) { return(new Div(ClpUtils.GetAssemblyLicenseText(EffectiveAssembly))); }
protected static Func <OptionInfo, bool> IsOptionVisible(HelpParts parts) => option => (option.IsVisible || parts.Has(HelpParts.HiddenOptions)) && (!option.IsBuiltIn || parts.Has(HelpParts.BuiltInOptions));
public static bool Has(this HelpParts @this, HelpParts flag) => (@this & flag) == flag;