private string GetHelpText(CommandLineApplication app)
        {
            var generator = new DefaultHelpTextGenerator
            {
                MaxLineLength = 80
            };

            return(GetHelpText(app, generator));
        }
        private string GetHelpText(CommandLineApplication app, DefaultHelpTextGenerator generator)
        {
            var sb = new StringBuilder();

            generator.Generate(app, new StringWriter(sb));
            var helpText = sb.ToString();

            _output.WriteLine(helpText);

            return(helpText);
        }
        private string GetHelpText(CommandLineApplication app, DefaultHelpTextGenerator generator, string helpOption = null)
        {
            var sb = new StringBuilder();

            app.Out = new StringWriter(sb);
            app.HelpTextGenerator = generator;
            app.Parse(helpOption ?? "-h");
            var helpText = sb.ToString();

            return(helpText);
        }
        public void DoesNotOrderCommandsByName()
        {
            var app = new CommandLineApplication <EmptyShortName>();

            app.Conventions.UseDefaultConventions();
            app.Command("b", _ => { });
            app.Command("a", _ => { });
            var generator = new DefaultHelpTextGenerator()
            {
                SortCommandsByName = false
            };
            var helpText = GetHelpText(app, generator);

            var indexOfA = helpText.IndexOf("  a", StringComparison.InvariantCulture);
            var indexOfB = helpText.IndexOf("  b", StringComparison.InvariantCulture);

            Assert.True(indexOfA > indexOfB);
        }
Пример #5
0
        public static async Task <int> Main(string[] args)
        {
            var htg = new DefaultHelpTextGenerator()
            {
                // Instead of alphabetical order, we list in definition order
                // which is more indicative of the typical usage order
                SortCommandsByName = false,
            };
            var cla = new CommandLineApplication <Program>()
            {
                // We override the default to control the display order of commands
                HelpTextGenerator = htg,
            };

            cla.Conventions
            .UseDefaultConventions()
            .UseConstructorInjection(ConfigureServices());

            return(await cla.ExecuteAsync(args));
        }