Example #1
0
        private static string BuildWebUsageString(CommandInfo commandRegistration, string commandPrefix)
        {
            string usage = $"{commandPrefix}{commandRegistration.PrimaryUsage.InvokeUsage}";

            foreach (var param in commandRegistration.Parameters.Where(x => !x.Flags.HasFlag(ParameterFlags.Hidden)))
            {
                string tmp = param.Name;
                if (param.Flags.HasFlag(ParameterFlags.Remainder))
                {
                    tmp += "...";
                }

                if (param.Flags.HasFlag(ParameterFlags.Optional))
                {
                    tmp = $"[{tmp}]";
                }

                usage += $" `{tmp}`";
            }

            var paramDescriptions = new StringBuilder();

            foreach (var param in commandRegistration.Parameters.Where(x => !x.Flags.HasFlag(ParameterFlags.Hidden) && !string.IsNullOrWhiteSpace(x.GetDescription(commandPrefix))))
            {
                string tmp = $"● `{param.Name}` ‒ ";
                if (param.Flags.HasFlag(ParameterFlags.Optional))
                {
                    tmp += "optional; ";
                }

                tmp += param.GetDescription(commandPrefix);
                paramDescriptions.Append(paramDescriptions.Length <= 0 ? tmp : "<br/>" + tmp);
            }

            var examples = commandRegistration.Examples
                           .Select(x => $"{commandPrefix}{commandRegistration.PrimaryUsage.InvokeUsage} {ConvertToHtml(x)}")
                           .DefaultIfEmpty()
                           .Aggregate((x, y) => x + "<br/>" + y);

            var result = new StringBuilder($"<span class=\"usagecode\">{ConvertToHtml(usage)}</span>");

            if (paramDescriptions.Length > 0)
            {
                result.Append("<br/><br/>" + ConvertToHtml(paramDescriptions.ToString()));
            }

            if (!string.IsNullOrWhiteSpace(commandRegistration.GetComment(commandPrefix)))
            {
                result.Append("<br/><br/>" + ConvertToHtml(commandRegistration.GetComment(commandPrefix)));
            }

            if (!string.IsNullOrWhiteSpace(examples))
            {
                result.Append("<br/><br/><u>Examples:</u><br/><code>" + ConvertToHtml(examples) + "</code>");
            }

            if (commandRegistration.Aliases.Any(x => !x.Hidden))
            {
                result.Append("<br/><span class=\"aliases\">Also as "
                              + commandRegistration.Aliases.Where(x => !x.Hidden).Select(x => $"<span class=\"alias\">{x.InvokeUsage}</span>").WordJoin(lastSeparator: " or ")
                              + "</span>");
            }

            return(result.ToString());
        }