Comments (5)
@JacobCZ adding this should fix it in the meantime!
...
var app = new CommandApp();
app.Configure(cfg => {
cfg.AddBranch("demo", d => {
d.AddDelegate<EmptyCommandSettings>("delegate", ctx => {
AnsiConsole.MarkupLine("[red]This doesn't work[/]");
return 0;
});
});
});
...
app.Run(args);
from spectre.console.
@FrankRay78 Do you know if any of the work we've done lately might have affected this?
from spectre.console.
It's be a long time since any core CLI changes have been made, so without stepping through the code/git history, I suspect it's been latent. Also, I've suspected for a while now, that branch behaviour, particularly branch of branch of branch, is not as thoroughly used/test covered, compared to default command, first level commands. I would guess there are other 'edge cases' like this, lying latent.
from spectre.console.
Looking at the Empty Configurator in the case you call .AddDelegate in this case
app.Configure(cfg =>
{
cfg.AddDelegate("a", _ =>
{
AnsiConsole.MarkupLine("[red]Complete[/]");
return 0;
});
});
It will default to using configurator.AddDelegate<EmptyCommandSettings>
but when called in this case
app.Configure(cfg =>
{
cfg.AddBranch("a", d =>
{
d.AddDelegate("b", _ =>
{
AnsiConsole.MarkupLine("[red]Complete[/]");
return 0;
});
});
});
It defaulted to using TSettings
even when no settings are supplied.
One possible solution is what I have attached in the diff below where we will check if the settings are abstract and if so fallback to EmptyCommandSettings.
I have added tests for these two use cases and can make a PR if this looks correct!
@@ -324,11 +324,16 @@
/// <param name="func">The delegate to execute as part of command execution.</param>
/// <returns>A command configurator that can be used to configure the command further.</returns>
public static ICommandConfigurator AddDelegate<TSettings>(
- this IConfigurator<TSettings> configurator,
+ this IConfigurator<TSettings>? configurator,
string name,
Func<CommandContext, int> func)
- where TSettings : CommandSettings
+ where TSettings : CommandSettings
{
+ if (typeof(TSettings).IsAbstract)
+ {
+ AddDelegate(configurator as IConfigurator<EmptyCommandSettings>, name, func);
+ }
+
if (configurator == null)
{
throw new ArgumentNullException(nameof(configurator));
from spectre.console.
I'd welcome a PR for this @BlazeFace, and I would prioritise its review with a view to merging.
from spectre.console.
Related Issues (20)
- Clickable tree nodes HOT 2
- How do you move -h|--help and -v|--version in the help text?
- "Input string was not in a correct format" error with `AnsiConsole.Write()` HOT 2
- Allow AnsiConsoleFactory to use a user provided IAnsiConsoleInput HOT 1
- Task< SomeReturnInfoClass > state = _app.RunAsyncWithState(args)
- Update table documentation example demonstrating cell borders
- Allow option to clear text after textprompt is answered
- Top Issues Dashboard
- Remove System.Memory dependency from net 6+ HOT 4
- Implement fixed-size log-text area for `ProgressTask` HOT 5
- Progress update causes heavy flickering (regression from 0.47.0 to 0.48.0) HOT 2
- Release a new version with support for InterceptResult as described in documentation HOT 1
- Sixlabors ImageSharp 3.X?
- Add interactive input fields HOT 1
- Built-in parameter `--version` conflicts with existing one HOT 9
- `ExplainCommand+Settings` ctor fails `ServiceProvider.ValidateService` HOT 1
- Bad rendering for table live display / hidden table headers / no border and forced refresh
- Search doesn't work properly in selection prompts HOT 1
- Add paging function to selection prompt
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spectre.console.