Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Agentew04/CliToolkit
A collection of tools to help the development of CLI and TUI tools
https://github.com/Agentew04/CliToolkit
Last synced: 21 days ago
JSON representation
A collection of tools to help the development of CLI and TUI tools
- Host: GitHub
- URL: https://github.com/Agentew04/CliToolkit
- Owner: Agentew04
- License: mit
- Created: 2023-11-19T19:31:00.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-01-30T00:51:51.000Z (12 months ago)
- Last Synced: 2024-01-30T02:08:47.773Z (12 months ago)
- Language: C#
- Homepage:
- Size: 34.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- RSCG_Examples - https://github.com/Agentew04/CliToolkit
README
# Cli.Toolkit
This project is mainly composed of a source generator that helps
the developer to create a command line interface for a .NET Core
application. It also contains many useful classes and methods.## CLI Helper
### Installation
The package is available on NuGet [here](https://www.nuget.org/packages/Cli.Toolkit/).
### Usage
The simplest program consists of a **partial** class with the `CLIProgram`
attribute and a method with the `Command` attribute.```cs
using CliToolkit.Attributes;[CliProgram]
public partial class MyCliTool {
[DefaultCommand]
[Command]
public void Add(Config args) {
// your command here
}
}
```The above code would be called like this:
```sh
$ myclitool add
```
or, as there is a command with the `DefaultCommand` attribute:
```sh
$ myclitool
```> **Note:** Only one method/command can have the `DefaultCommand` attribute.
## Source Generators
Many useful source generators are present, and automate the implementation
of features, such as:
* Builder Pattern
* Lazy Singleton
* Thread Safety for a field### Usage
The generators are located in the namespace `Cli.Toolkit.Generators` and
the attributes to trigger them are normally located in the namespace
`Cli.Toolkit.Attributes`.```csharp
using Cli.Toolkit.Generators;
using Cli.Toolkit.Attributes;// partial modifier is required to use source generators
public partial class Program {
// these fields are not required to be static,
// but is needed if used directly in the Main method(static)
[Lazy]
private static Config? cfg; // Generates the Cfg property
[ThreadSafe]
private static int _number = 5; // Generates the Number property
public static void Main() {
// use them here
// ...
}
}
``````csharp
using Cli.Toolkit.Generators;
using Cli.Toolkit.Attributes;// annotating the class
// both properties and fields are supported
[Buildable]
public class Hamburger {
public List Ingredients { get; set; } = new();
public int price;
}// using the new builder
Hamburger hamburger = new HamburgerBuilder()
.WithIngredients([ "Bread", "Meat", "Cheese" ])
.WithPrice(5)
.Build();
```