spectre.console icon indicating copy to clipboard operation
spectre.console copied to clipboard

Don't show command examples at root

Open patriksvensson opened this issue 4 years ago • 2 comments

Only examples specified on the root should show at the root. If examples are specified for commands it should not show up at the root since this is a bit confusing.

patriksvensson avatar Aug 23 '20 09:08 patriksvensson

Hi, this is really an issue where you have complex sub commands and you need to show a list of examples per sub command. Hope this gets scheduled for fix in the next release, btw fantastic library! 👏

libe avatar Jun 18 '22 14:06 libe

@libe Thank you! I'm currently on vacation until August and haven't really planned on working a lot on Spectre.Console during this time, but if you feel that this is important, a PR is always appreciated! 😊

patriksvensson avatar Jun 19 '22 09:06 patriksvensson

Hi @patriksvensson, I have marked this issue as being fully address by PR https://github.com/spectreconsole/spectre.console/pull/1252, not because it removes the default behaviour of displaying examples from direct children when the root contains none. Rather because you can now turn this behaviour off, if desired, by configurator.Settings.MaximumIndirectExamples = 0; Alternatively, this is also now possible:

            fixture.Configure(configurator =>
            {
                configurator.SetApplicationName("myapp");

                // Show the first 8 examples defined on the direct children
                configurator.Settings.MaximumIndirectExamples = 8;

                configurator.AddCommand<DogCommand>("dog")
                    .WithExample("dog", "--name", "Rufus", "--age", "12", "--good-boy")
                    .WithExample("dog", "--name", "Luna")
                    .WithExample("dog", "--name", "Charlie")
                    .WithExample("dog", "--name", "Bella")
                    .WithExample("dog", "--name", "Daisy")
                    .WithExample("dog", "--name", "Milo");

                configurator.AddCommand<HorseCommand>("horse")
                    .WithExample("horse", "--name", "Brutus")
                    .WithExample("horse", "--name", "Sugar", "--IsAlive", "false")
                    .WithExample("horse", "--name", "Cash")
                    .WithExample("horse", "--name", "Dakota")
                    .WithExample("horse", "--name", "Cisco")
                    .WithExample("horse", "--name", "Spirit");
            });

At one point in the PR, I had removed the code to display examples from children entirely, but felt it was heavyhanded and may have removed what could be quite a useful default behaviour. For example, the issue https://github.com/spectreconsole/spectre.console/issues/1180 (which is quite a bit newer than this one) makes no mention of the need to remove the default behaviour.

Anyhow, that's a more in-depth explanation of why the PR has been implemented as it has been.

FrankRay78 avatar Jul 05 '23 10:07 FrankRay78