Comments (6)
In 2.0.0-beta4.22272.1, the "Required command was not provided" error is set by ParseResultVisitor.ValidateCommandHandler if the user-specified command does not have a handler but has subcommands. This is called during Parser.Parse. Your code above calls builder.UseCommandHandler<DefaultRootCommand, DefaultRootCommand.Handler>()
but I think this is executed too late and the parser has already made its decision. Perhaps you could work around this by assigning a dummy handler to the command initially, just to satisfy the parser; the hosting middleware would then substitute the correct handler after parsing finishes, so the dummy handler would never be called.
from command-line-api.
@elgonzo, the constructor is public RootCommand(string description = "")
.
from command-line-api.
In 2.0.0-beta4.22272.1, the "Required command was not provided" error is set by ParseResultVisitor.ValidateCommandHandler if the user-specified command does not have a handler but has subcommands. This is called during Parser.Parse. Your code above calls
builder.UseCommandHandler<DefaultRootCommand, DefaultRootCommand.Handler>()
but I think this is executed too late and the parser has already made its decision. Perhaps you could work around this by assigning a dummy handler to the command initially, just to satisfy the parser; the hosting middleware would then substitute the correct handler after parsing finishes, so the dummy handler would never be called.
The workaround I found is create sub command and keep RootCommand
handler empty like you said.
builder.UseCommandHandler<DefaultRootCommand, ICommandHandler>();
from command-line-api.
No, I meant you'd assign a dummy handler to the root command without UseCommandHandler
, then let UseCommandHandler
replace it with the real handler after parsing has finished.
from command-line-api.
No, I meant you'd assign a dummy handler to the root command without
UseCommandHandler
, then letUseCommandHandler
replace it with the real handler after parsing has finished.
But how would i do that if I was doing this for example:
internal sealed partial class DefaultRootCommand : RootCommand
{
public DefaultRootCommand() : base("Description")
{
var openWalletCommand = new OpenWalletCommand();
var startOption = new Option<bool>("--as-service", "Option1");
AddCommand(openWalletCommand);
AddOption(startOption);
}
public new sealed class Handler : ICommandHandler
{
public int Invoke(InvocationContext context)
{
// TODO: Add Code
}
public Task<int> InvokeAsync(InvocationContext context)
{
// TODO: Add Code
}
}
}
from command-line-api.
By assigning Command.Handler or calling some overload of Handler.SetHandler. For example, this.SetHandler((InvocationContext _) => {});
.
from command-line-api.
Related Issues (20)
- Replace `ParseError`/string errors with `Error` and use generally HOT 7
- Create error reporting output HOT 1
- [Proposal] Validation
- Some naming and organizational issues
- [Proposal] Diagramming
- [Proposal] Remove `TreatUnmatchedTokensAsErrors` HOT 7
- HostingAction for options handlers HOT 3
- HostingAction wrapper does not honor Terminating flag of original action
- [Proposal] Remove global options in Powderhouse parser HOT 3
- [Proposal] Unifying public parts of ArgumentResult and OptionResult to ValueResult and isolating parser support HOT 2
- [Proposal] ValueSubsystem - default values HOT 1
- BinderBase functionality replacement HOT 1
- [Proposal] Values API HOT 1
- EnvironmentDirective has a hard-coded call to Environment.SetEnvironmentVariable making it hard to test
- Breaking changes for Powderhouse
- Usage root command does not display `ToolCommandName` HOT 1
- [Breaking] Remove CommandResult HOT 6
- Powderhouse support for .NET versions
- Tracking issue for Error changes
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 command-line-api.