Пример #1
0
 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));
 }
Пример #2
0
 private object GetAssemblyLicenseCore(HelpParts parts)
 {
     if (!parts.Has(HelpParts.AssemblyLicense))
     {
         return(null);
     }
     return(GetAssemblyLicense(parts));
 }
Пример #3
0
 private object GetAssemblyTitleCore(HelpParts parts)
 {
     if (!parts.Has(HelpParts.AssemblyTitle | HelpParts.AssemblyVersion))
     {
         return(null);
     }
     return(GetAssemblyTitle(parts));
 }
Пример #4
0
 private object GetUsageCore(HelpParts parts)
 {
     if (!parts.Has(HelpParts.AssemblyUsage))
     {
         return(null);
     }
     return(GetUsage(parts));
 }
Пример #5
0
 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));
 }
Пример #6
0
 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));
 }
Пример #7
0
 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));
 }
Пример #8
0
 private object GetAssemblyCopyrightCore(HelpParts parts)
 {
     if (!parts.Has(HelpParts.AssemblyCopyright))
     {
         return(null);
     }
     return(GetAssemblyCopyright(parts));
 }
Пример #9
0
        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));
        }
Пример #10
0
 protected virtual object GetHeader(HelpParts parts)
 {
     return(new Div {
         Color = AssemblyMetaColor,
         Children =
         {
             GetAssemblyTitleCore(parts),
             GetAssemblyCopyrightCore(parts),
             GetAssemblyLicenseCore(parts),
             Header,
         }
     });
 }
Пример #11
0
 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)));
 }
Пример #12
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),
         }
     });
 }
Пример #13
0
        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));
        }
Пример #14
0
 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)
                 }
             }
         }
     });
 }
Пример #15
0
 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))
         }
     });
 }
Пример #16
0
        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
            });
        }
Пример #17
0
        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
                    },
                }
            });
        }
Пример #18
0
 private Document Message(object errorsSource, HelpParts parts = HelpParts.Errors) => With(errorsSource: errorsSource).Help(parts);
Пример #19
0
 protected virtual object GetErrors(HelpParts parts)
 {
     return(Info.Errors.Where(e => e.Message != null).Select(GetError));
 }
Пример #20
0
 public Document Message(ErrorInfo error, HelpParts parts = HelpParts.Errors) => Message((object)error, parts);
Пример #21
0
 public Document Message(IEnumerable <ErrorInfo> errors, HelpParts parts = HelpParts.Errors) => Message((object)errors, parts);
Пример #22
0
 protected virtual object GetFooter(HelpParts parts)
 {
     return(new Div(Footer));
 }
Пример #23
0
 protected virtual object GetAssemblyLicense(HelpParts parts)
 {
     return(new Div(ClpUtils.GetAssemblyLicenseText(EffectiveAssembly)));
 }
Пример #24
0
 protected static Func <OptionInfo, bool> IsOptionVisible(HelpParts parts) =>
 option => (option.IsVisible || parts.Has(HelpParts.HiddenOptions)) && (!option.IsBuiltIn || parts.Has(HelpParts.BuiltInOptions));
Пример #25
0
 public static bool Has(this HelpParts @this, HelpParts flag) => (@this & flag) == flag;