Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tyevco/TeCLI
CLI Tool for C#
https://github.com/tyevco/TeCLI
Last synced: about 1 month ago
JSON representation
CLI Tool for C#
- Host: GitHub
- URL: https://github.com/tyevco/TeCLI
- Owner: tyevco
- License: mit
- Created: 2024-04-30T16:49:48.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-05-06T17:51:39.000Z (7 months ago)
- Last Synced: 2024-08-01T22:44:14.368Z (4 months ago)
- Language: C#
- Size: 97.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- RSCG_Examples - tecli
README
### 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.
```bash
dotnet add package TeCLI
```##### Basic Setup
1. **Define Commands**
Use the `CommandAttribute` to mark classes that represent CLI commands:
```csharp
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:
```csharp
[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`:
```csharp
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.