Skip to content

azachert/CommandLine.Commands

Repository files navigation

CommandLine.Commands

Build status

Production CI
Build status Build status

Introduction

This is an extension to CommandLineParser project.

Usage

Create your options class

[Verb("add")]
internal class AddOptions
{
}

Create your command handler class

internal class AddCommand : Command<AddOptions>
{
        public override async Task<int> ExecuteAsync(AddOptions options)
        {
            // do your magic here
            // and return some value
        }
}

Handle input arguments in Program.Main

class Program 
{
    public static async Task<int> Main(IEnumerable<string> args)
    {
        var commands = new ICommand[] 
        {
	        new AddCommand(),
	        // add your other commands here
        };

        return await Parser.Default.ParseArguments(args, commands)
            .WithNotParsed(result =>
            {
                // handle error
            })
            .WithParsedAsync(commands);	
    }
}

Copyrights & License

Copyrights © Arkadiusz Zachert

This software is licensed based on MIT License

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages