Skip to content

Support for commands #127

Description

@ericnewton76

Issue by fleed
Friday Mar 31, 2017 at 04:24 GMT
Originally opened as gsscoder/commandline#434


Is there any existing way to define commands, intended as classes to execute specific options? IF not, any plan to add support? I would expect something like this, removing lot of the ceremony required to configure the option and run the related logic:

Example:

class CommitCommand : Command<CommitOptions>
{
    public int Execute(CommitOptions options)
    {
        // execute
        return 0;
    }

    // alternative
    public int Execute()
    {
        // access options as property in AsyncCommand base
        var file = this.Options.File;

        // execute
        return 0;
    }
}

class UploadCommand : AsyncCommand<UploadOptions>
{
    public async Task<int> ExecuteAsync(CommitOptions options)
    {
        // execute
        return 0;
    }

    // alternative
    public async Task<int> ExecuteAsync()
    {
        // access options as property in AsyncCommand base
        var file = this.Options.File;

        // execute
        return 0;
    }
}

// Program.cs
var parser = new CommandParser();
var parserResult = parser.Parse(args);
var result = parserResult.ExecuteCommand();

In general I'd like the possibility to discover options and commands through reflection, something similar to ManyConsole.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions