TeCLI 0.2.5

dotnet add package TeCLI --version 0.2.5
NuGet\Install-Package TeCLI -Version 0.2.5
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TeCLI" Version="0.2.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TeCLI --version 0.2.5
#r "nuget: TeCLI, 0.2.5"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TeCLI as a Cake Addin
#addin nuget:?package=TeCLI&version=0.2.5

// Install TeCLI as a Cake Tool
#tool nuget:?package=TeCLI&version=0.2.5

Developer Documentation for TeCLI

Introduction

TeCLI is a source-generated CLI parsing library designed to simplify the development of command-line interfaces in .NET applications. It uses custom attributes to mark classes and methods as commands and subcommands, automatically generating the necessary parsing and dispatching logic.

Features
  • Command and Subcommand Handling: Define commands and optional subcommands using attributes.
  • Argument Parsing: Automatically parse command line arguments into primitive types or custom classes with parameterized constructors.
  • Help Generation: Automatically generate help menus based on command and subcommand descriptions.
Getting Started
Installation

To use TeCLI in your project, add a reference to the TeCLI library. You can include it as a project in your solution or as a NuGet package if it is available in that form.

dotnet add package TeCLI
Basic Setup
  1. Define Commands

    Use the CommandAttribute to mark classes that represent CLI commands:

    using TeCLI;
    
    [Command("greet", Description = "Greets the user")]
    public class GreetCommand
    {
    }
    
  2. Define Actions

    Use the ActionAttribute for methods that should be executed as part of a command:

    [PrimaryAction(Description = "Say hello")]
    public void Hello(string name)
    {
        Console.WriteLine($"Hello, {name}!");
    }
    
Example Usage

To use the defined commands, ensure your application's entry point calls the generated CommandDispatcher:

public class Program
{
    public static void Main(string[] args)
    {
        CommandDispatcher.Dispatch(args);
    }
}
How to Define Commands

Commands are classes annotated with the CommandAttribute, which includes properties for the command name and an optional description. Each command can have multiple actions, which are methods annotated with ActionAttribute.

  • Command Attribute: Marks a class as a command with a specific command name.
  • Action Attribute: Marks methods within command classes to be callable actions. The PrimaryAttribute is used for the default action if no specific action is called.
Extending Functionality

TeCLI is designed to be extensible:

  • Adding New Commands: Simply create a new class with the CommandAttribute and define methods with ActionAttribute.
  • Custom Argument Parsers: Implement custom parsing logic for complex types by defining a constructor or conversion method that takes a string argument.
FAQs
  • How do I handle optional arguments?

    Use properties in your command classes with default values to handle optional arguments.

  • Can I override the help generation?

    Currently, the help menu is automatically generated, but you can extend the dispatcher to customize help messages.

Contributing

Contributions are welcome! To contribute, please fork the repository, make your changes, and submit a pull request.

Conclusion

This documentation provides the basic information necessary for developers to get started with TeCLI, understand its structure, and begin integrating and extending it within their own projects. Make sure to expand on each section with more specific examples and detailed descriptions as needed to address all potential user concerns and use cases.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.2.5 93 5/6/2024