GithubHelp home page GithubHelp logo

command-line-api-generator's Introduction

NuGet

System.CommandLine.SourceGenerator

Enhance your .NET CLI applications with dynamic command-line interface (CLI) capabilities using System.CommandLine.SourceGenerator. This package leverages the power of source generators to automatically create robust RootCommand code, simplifying the development of complex CLI tools.

Getting Started

To incorporate System.CommandLine.SourceGenerator into your project, simply install the package via NuGet:

Install-Package Evan.System.CommandLine.SourceGenerator
Install-Package Evan.System.CommandLine.SourceGenerator.Common

Defining Commands

[RootCommand(Handler = typeof(AppCommandHandler))]
class AppCommand
{
    [Option("verbose", IsRequired = false, Description = "Set output to verbose messages.")]
    public bool Verbose { get; set; }

    [Command("config")]
    class Config
    {
        [Command("get", Handler = typeof(ConfigGetCommandHandler))]
        class GetCommand
        {
            [Argument("key", Description = "The configuration key to retrieve.")]
            public string Key { get; set; }
        }
    }
}

Implementing Command Handlers

Implement handlers for your commands to define the logic executed when commands are invoked:

class AppCommandHandler : ICommandHandler<AppCommand>
{
    public Task<int> InvokeAsync(AppCommand command)
    {
        // Implementation logic here...
    }
}

class ConfigGetCommandHandler : ICommandHandler<AppCommand.Config.GetCommand>
{
    public Task<int> InvokeAsync(AppCommand.Config.GetCommand command)
    {
        // Implementation logic here...
    }
}

Execution

Bootstrap and run your application by invoking the command handler from your program's entry point:

static async Task Main(string[] args)
{
    var command = AppCommandFactory.Create();
    Environment.ExitCode = await command.InvokeAsync(args);
}

command-line-api-generator's People

Contributors

evan-choi avatar

Stargazers

 avatar  avatar Lee Seung Hu avatar Tony Jang (장유탁) avatar

Watchers

 avatar

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.