Git Product home page Git Product logo

Comments (6)

KalleOlaviNiemitalo avatar KalleOlaviNiemitalo commented on June 12, 2024

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.

KalleOlaviNiemitalo avatar KalleOlaviNiemitalo commented on June 12, 2024

@elgonzo, the constructor is public RootCommand(string description = "").

from command-line-api.

cschuchardt88 avatar cschuchardt88 commented on June 12, 2024

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.

KalleOlaviNiemitalo avatar KalleOlaviNiemitalo commented on June 12, 2024

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.

cschuchardt88 avatar cschuchardt88 commented on June 12, 2024

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.

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.

KalleOlaviNiemitalo avatar KalleOlaviNiemitalo commented on June 12, 2024

By assigning Command.Handler or calling some overload of Handler.SetHandler. For example, this.SetHandler((InvocationContext _) => {});.

from command-line-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.