Exemple #1
0
        public static string GetHelp(this CliExecutorDescriptor descriptor)
        {
            var margin    = 20;
            var maxLength = 20;

            var sb          = new StringBuilder();
            var helpBuilder = new HelpBuilder();

            sb.AppendLine(descriptor.Description);
            if (descriptor.UsageSamples.Any())
            {
                sb.AppendLine();
                sb.AppendLine("Usage samples:");
                foreach (var usageSample in descriptor.UsageSamples)
                {
                    sb.AppendLine(usageSample);
                }
            }

            if (descriptor.Keys.Any())
            {
                sb.AppendLine();
                sb.AppendLine("Keys:");

                foreach (var key in descriptor.Keys)
                {
                    sb.Append(string.Join(", ", key.Keys));

                    var docSubstitution = key.ValueDescriptor.DocSubstitution ?? $"{key.Alias}";

                    sb.Append($" <{docSubstitution}>");

                    helpBuilder.WriteHelp(sb, key.ValueDescriptor.Description, margin, maxLength);
                }
            }

            if (descriptor.Arguments.Any())
            {
                sb.AppendLine();
                sb.AppendLine("Arguments:");
                foreach (var argument in descriptor.Arguments)
                {
                    var docSubstitution = argument.DocSubstitution ?? $"{argument.Alias}";

                    sb.Append($"<{docSubstitution}>");

                    helpBuilder.WriteHelp(sb, argument.Description, margin, maxLength);
                }
            }

            if (descriptor.Options.Any())
            {
                sb.AppendLine();
                sb.AppendLine("Options:");
                foreach (var option in descriptor.Options)
                {
                    sb.Append(string.Join(", ", option.Options));

                    helpBuilder.WriteHelp(sb, option.Description, margin, maxLength);
                }
            }

            return(sb.ToString());
        }