-
-
Notifications
You must be signed in to change notification settings - Fork 519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Showing Mutiple Examples #1180
Comments
@RealDotNetDave Only 5 examples are shown from the commands(when examples are not added at the root). If you can remove few examples from the first command and check, may be it will confirm. |
Yes, after removing a few of the examples, the ones for the second command showed up. Is there a 5 example limit? |
@RealDotNetDave If the example isn't specific to the current command, the max number of examples is 5: https://github.com/spectreconsole/spectre.console/blob/main/src/Spectre.Console.Cli/Internal/HelpWriter.cs#L186 |
Oh, I did not see that. Thanks. |
How do I get the examples to show up when someone uses --help? |
Running |
@FrankRay78 What are your thoughts on this? |
When I removed the examples, they stopped showing up when I run --help. Maybe WithExample needs a flag on where to show it? |
There are a few bugs/feature requests related to examples, branches and help. Somewhat overlapping in functionality. Now that the 0.47.0 release is out of the way I'm happy to spend some time this week looking into this and the others. I can provide an update once I've made some progress investigating... perhaps also prepare a branch for you to test on @RealDotNetDave |
Update: I've cleared my backlog of open-source issues and can look at this next. |
So, I've had a proper look at this now... Issue 1. Max 5 examplesThere is an arbitary restriction of displaying only 5 examples (as highlighted above), which could easily be made configurable if required. Let me know if that would be useful @RealDotNetDave . Issue 2. Display examples in an intuitive and user-friendly mannerThe behaviour I would generally expect for displaying examples is that only examples relating to the specified command to be shown, and if at the root, then the examples added through Scenarios
Notes
Testing how examples are displayed in scenarios 1 - 4 aboveI used the following console app code to 'replicate' @RealDotNetDave's application: using Spectre.Console;
using Spectre.Console.Cli;
public class Program
{
public static void Main(string[] args)
{
var app = new CommandApp();
app.SetDefaultCommand<EchoCommand>();
app.Configure(config =>
{
config.PropagateExceptions();
config.AddExample("xyz", "--argument1");
config.AddExample("xyz", "--argument1", "--argument2");
//Clean commands
config.AddCommand<EchoCommand>("clean")
.WithDescription("Clean temp and cached files generated by Visual Studio, SQL Server and more")
.WithExample(new[] { "clean" })
.WithExample(new[] { "clean", "--af", "c:\\temp" })
.WithExample(new[] { "clean", "--addfolder", "c:\\temp" })
.WithExample(new[] { "clean", "--rf", "c:\\temp" })
.WithExample(new[] { "clean", "--removefolder", "c:\\temp" })
.WithExample(new[] { "clean", "--sixth-example-to-demonstrate-truncation" });
//Backup commands
config.AddCommand<EchoCommand>("backup")
.WithDescription("Backup code of Visual Studio solutions")
.WithExample(new[] { "backup" })
.WithExample(new[] { "backup", "--turbo" })
.WithExample(new[] { "backup", "--af", "c:\\temp" })
.WithExample(new[] { "backup", "--addfolder", "c:\\temp" })
.WithExample(new[] { "backup", "--rf", "c:\\temp" })
.WithExample(new[] { "backup", "--removefolder", "c:\\temp" })
.WithExample(new[] { "backup", "--sixth-example-to-demonstrate-truncation" });
});
app.Run(args);
}
}
public class EchoCommand : Command
{
private readonly IAnsiConsole _console;
public EchoCommand(IAnsiConsole console)
{
_console = console;
}
public override int Execute(CommandContext context)
{
_console.WriteLine($"Command: {context.Name}");
return 0;
}
} I commented out/uncommented the following sections to exercise all 4 combinations, compiling and running scenarios 1 - 4 above each time to fully exercise spectre.console's handling of examples: OutcomeScenarios 1 - 4 above generally behaved as expected (ie. only examples relating to the specified command to be shown), except for the following issues which were discovered: (nb. with regard to the following screenshots, my console app is called Issue 1. Examples for child commands are incorrectly showingWith the following main function, compile the console application. public static void Main(string[] args)
{
var app = new CommandApp();
//app.SetDefaultCommand<EchoCommand>();
app.Configure(config =>
{
config.PropagateExceptions();
//config.AddExample("xyz", "--argument1");
//config.AddExample("xyz", "--argument1", "--argument2");
//Clean commands
config.AddCommand<EchoCommand>("clean")
.WithDescription("Clean temp and cached files generated by Visual Studio, SQL Server and more")
.WithExample(new[] { "clean" })
.WithExample(new[] { "clean", "--af", "c:\\temp" })
.WithExample(new[] { "clean", "--addfolder", "c:\\temp" })
.WithExample(new[] { "clean", "--rf", "c:\\temp" })
.WithExample(new[] { "clean", "--removefolder", "c:\\temp" })
.WithExample(new[] { "clean", "--sixth-example-to-demonstrate-truncation" });
//Backup commands
config.AddCommand<EchoCommand>("backup")
.WithDescription("Backup code of Visual Studio solutions")
.WithExample(new[] { "backup" })
.WithExample(new[] { "backup", "--turbo" })
.WithExample(new[] { "backup", "--af", "c:\\temp" })
.WithExample(new[] { "backup", "--addfolder", "c:\\temp" })
.WithExample(new[] { "backup", "--rf", "c:\\temp" })
.WithExample(new[] { "backup", "--removefolder", "c:\\temp" })
.WithExample(new[] { "backup", "--sixth-example-to-demonstrate-truncation" });
});
app.Run(args);
} Run Actual resultYikes, it arbitrarily/incorrectly displays the examples for the Expected resultIt should not display any examples (ie. it should be the same behaviour for when the default command has been added but without any examples): Issue 2. Command argument missing, version option missingWith the following main function, compile the console application. public static void Main(string[] args)
{
var app = new CommandApp();
app.SetDefaultCommand<EchoCommand>(); // <-- UNCOMMENTED
app.Configure(config =>
{
config.PropagateExceptions();
//config.AddExample("xyz", "--argument1");
//config.AddExample("xyz", "--argument1", "--argument2");
//Clean commands
config.AddCommand<EchoCommand>("clean")
.WithDescription("Clean temp and cached files generated by Visual Studio, SQL Server and more")
.WithExample(new[] { "clean" })
.WithExample(new[] { "clean", "--af", "c:\\temp" })
.WithExample(new[] { "clean", "--addfolder", "c:\\temp" })
.WithExample(new[] { "clean", "--rf", "c:\\temp" })
.WithExample(new[] { "clean", "--removefolder", "c:\\temp" })
.WithExample(new[] { "clean", "--sixth-example-to-demonstrate-truncation" });
//Backup commands
config.AddCommand<EchoCommand>("backup")
.WithDescription("Backup code of Visual Studio solutions")
.WithExample(new[] { "backup" })
.WithExample(new[] { "backup", "--turbo" })
.WithExample(new[] { "backup", "--af", "c:\\temp" })
.WithExample(new[] { "backup", "--addfolder", "c:\\temp" })
.WithExample(new[] { "backup", "--rf", "c:\\temp" })
.WithExample(new[] { "backup", "--removefolder", "c:\\temp" })
.WithExample(new[] { "backup", "--sixth-example-to-demonstrate-truncation" });
});
app.Run(args);
} Run Actual resultThe help text does not include a placeholder for commands and also the version option is missing Expected result |
Sounds like lifting this restriction is what you are after. |
This should be fixed already @RealDotNetDave, the default number of examples shown (across child commands at the same level) is 5 (to retain backward compatibility), however there is now the ability to override this. eg //nb. show 8 examples
config.Settings.MaximumIndirectExamples = 8; There is a unit test covering exactly your issue above, see here:
I'm going to close this issue, but feel free to ping me if there is anything else you need help with. |
I am setting examples (see below), but when I run the program, I do not see the examples from the backup command. Am I doing something wrong?
The text was updated successfully, but these errors were encountered: