Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jden123/JustCli
Just a quick way to create your own command line tool
https://github.com/jden123/JustCli
Last synced: about 2 months ago
JSON representation
Just a quick way to create your own command line tool
- Host: GitHub
- URL: https://github.com/jden123/JustCli
- Owner: jden123
- License: mit
- Created: 2015-12-30T10:33:23.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2021-02-23T04:20:15.000Z (almost 4 years ago)
- Last Synced: 2024-10-03T03:21:41.346Z (2 months ago)
- Language: C#
- Homepage:
- Size: 1.15 MB
- Stars: 29
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-csharp - JustCli - That’s just a quick way to create your own command line tool. (CLI)
- awesome-dotnet-cn - JustCli - 快速创建你自己命令行工具的方法。 (CLI)
- awsome-dotnet - JustCli - That’s just a quick way to create your own command line tool. (CLI)
- awesome-dotnet - JustCli - That’s just a quick way to create your own command line tool. (CLI)
README
JustCli
===
That’s just a quick way to create your own command line tool.The idea is to have one command in one class. A set of attributes helps you to map command line arguments to the command class properties and provide additional information. JustCli scans your project, generates help and allows you to run the commands.
Download
---
You can install it using [NuGet](https://www.nuget.org/packages/JustCli/).Example
---
Let’s create a “*sayhello*” command.
First of all we need a console application with JustCli entry point.
```csharp
static int Main(string[] args)
{
return CommandLineParser.Default.ParseAndExecuteCommand(args);
}
```
Create SayHelloCommand class and implement command logic.
```csharp
[Command(
"sayhello",
"Prints a greeting.",
@"Very useful command that print hello to the output with the word you provide.
This command is greatly described in this help text so you should be able to use it properly after you read it.
More examples at http://hello.world/greetings/examples")]
class SayHelloCommand : ICommand
{
[CommandArgument("n", "name", Description = "The someone to greet.", DefaultValue = "World")]
public string Name { get; set; }[CommandOutput]
public IOutput Output { get; set; }public int Execute()
{
Output.WriteInfo("Hello {0}!", Name);
return ReturnCode.Success;
}
}
```
CommandOutput attribute marks property where the common output is injected. Colored console is used by default.When run the command line tool we can see command list.
```
cmd> TestApp.exe
Command list:
sayhello - Prints a greeting.
```
Also you can get help for a special command.
```
cmd> TestApp.exe sayhello ?
sayhello - Prints a greeting.
Very useful command that print hello to the output with the word you provide.
This command is greatly described in this help text so you should be able to use it properly after you read it.
More examples at http://hello.world/greetings/examples
Options:
-n --name [string] The someone to greet. [default: World]
```
That is what JustCli makes for you.Let's test "*sayhello*" command.
```
cmd> TestApp.exe sayhello
Hello World!
cmd> TestApp.exe sayhello -n Bob
Hello Bob!
```
Now you know how to create command line tool quickly and easily! :)