Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/scott-the-programmer/cli.commandhandler
An easy way to build map command models to their corresponding handlers
https://github.com/scott-the-programmer/cli.commandhandler
Last synced: 16 days ago
JSON representation
An easy way to build map command models to their corresponding handlers
- Host: GitHub
- URL: https://github.com/scott-the-programmer/cli.commandhandler
- Owner: scott-the-programmer
- Created: 2021-06-27T05:56:30.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-07-13T10:28:57.000Z (over 3 years ago)
- Last Synced: 2024-11-07T20:55:13.544Z (2 months ago)
- Language: C#
- Size: 19.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# CLI.CommandHandler
This is currently a WIP
## Intent
This project aims to automatically map cli command models to corresponding command handlers. The overall goal is to eliminate manual command line arg parsing, and allow developers to focus on the logic.
At its current state, this project is highly coupled to https://github.com/commandlineparser/commandline
## Example
### Command Model
```csharp
[Verb("make-noise")]
public class MakeNoise : ICommand
{
[Option('n', "noise", Required = true, HelpText = "Noise to emit")]
public string Noise { get; set; }
}
```### Command Handler
```csharp
public class MakeNoiseCommand : ICommandHandler
{
public Task HandleAsync(MakeNoise command)
{
Console.WriteLine(command.Noise)
return Task.CompletedTask;
}
}
```### Program.cs
```csharp
public static void Main(string[] args)
{
var types = LoadRunCommands(); //TODO: Define this a bit betterParser.Default.ParseArguments(args, types)
.WithParsed(Run);Console.ReadLine();
}public static void Run(object command)
{
var commandDispatcher = new CommandDispatcher(Assembly.GetExecutingAssembly().GetName());
commandDispatcher.DispatchAsync(command) //Run the MakeNoise command
}
```