IgniteCLI 1.0.0
dotnet add package IgniteCLI --version 1.0.0
NuGet\Install-Package IgniteCLI -Version 1.0.0
<PackageReference Include="IgniteCLI" Version="1.0.0" />
paket add IgniteCLI --version 1.0.0
#r "nuget: IgniteCLI, 1.0.0"
// Install IgniteCLI as a Cake Addin
#addin nuget:?package=IgniteCLI&version=1.0.0
// Install IgniteCLI as a Cake Tool
#tool nuget:?package=IgniteCLI&version=1.0.0
Ignite CLI
Ignite is a library for creating CLI applications in .NET Core
Overview
Ignite helps you quickly create and augment your .NET Core Console App projects. When Ignite is given a list of Commands, set up is complete. Ignite will parse and convert user input automatically then trigger the given functions with the appropriate arguments.
Getting Started
- Create a new .NET Console App (.NET Core 2.0) project
- Follow Installation
- Declare and define a
CommandList
- Run
CLI.Start(MyCommandList)
in thestatic void Main(string[] args)
method that's provided with Console Apps
Installation
To install Ignite simply find the package in the Nuget package browser or run
Install-Package IgniteCLI
NOTE: .NET Core 2.0 is required in order to use Ignite.
Usage
API
CLI.Start(CommandList commands)
- This method is what initializes Ignite with the given
CommandList
- This method is what initializes Ignite with the given
Printing
Ignite provides multiple methods for output, including the ability to customize color
CLI.Help()
- Help prints out the
CommandList
in an easy-to-read format
- Help prints out the
CLI.Break()
- Outputs a line of hypens to a new line in the Console
CLI.Out(string s = "")
- Outputs
s
to a new line in the Console
- Outputs
CLI.Out(string s, ConsoleColor fore, ConsoleColor back = ConsoleColor.Black)
- Outputs
s
to a new line in the Console with the given foreground and background color
- Outputs
Dynamic
Ignite lets you simulate user input for programmatic command execution
CLI.Run(string command, params string[] args)
- Runs the
command
with the providedargs
as if they were typed into the Console by a user - Example:
CLI.Run("add", "a 10", "b 5")
- Example:
CLI.Run("add", new string[2] {"a 10", "b 5"})
- Runs the
CLI.Run(params string[] input)
- Extracts the first element in the array and calls the above
CLI.Run()
passing that in as thecommand
and the rest as theargs
- Example:
CLI.Run("add", "a 10", "b 5")
- Example:
CLI.Run(new string[3] {"add", "a 10", "b 5"})
- Extracts the first element in the array and calls the above
Parsing Arguments
During command functions, Ignite provides quick methods to automatically parse and convert arguments
CLI.String(Dictionary<string, string> d, string key)
- Parses the value from the
Dictionary<string, string>
as a String
- Parses the value from the
CLI.Int(Dictionary<string, string> d, string key)
- Parses the value from the
Dictionary<string, string>
as a Int
- Parses the value from the
CLI.Bool(Dictionary<string, string> d, string key)
- Parses the value from the
Dictionary<string, string>
as a Bool - "true" and "false" are evaluated appropriately
- When no value is given, it is evaluated as true
- Parses the value from the
Commands
Structure
public static CommandList Commands = new CommandList
{
new Command
{
Name = "mycommand",
Description = "Executes My Command with the given arguments",
Args = new CommandArgs
{
new CommandArg
{
Tag = "string-in",
InputFormat = "Informs user of the value to provide for 'string-in'",
Description = "(str) This is my first CommandArg named 'string-in'",
//Required = true by default
},
},
Function = args =>
{
string input = CLI.String(args, "string-in");
if(String.IsNullOrEmpty(input)) CLI.Help(); //No input given, show help
else
{
CLI.Out(MyCommand(input));
}
}
},
}
Example
new Command
{
Name = "add",
Description = "Add two numbers together",
Args = new CommandArgs
{
new CommandArg
{
Tag = "a",
InputFormat = "first number",
Description = "(int) The first number in the equation",
},
new CommandArg
{
Tag = "b",
InputFormat = "second number",
Description = "(int) The second number in the equation",
}
},
Function = args =>
{
int a = CLI.Int(args, "a");
int b = CLI.Int(args, "b");
CLI.Out($"{a} + {b} = {a + b}", ConsoleColor.Green);
}
},
Expected Output
Generated Help
Sample Program
This is an example of a simple CLI made with Ignite.
using System;
using IgniteCLI;
namespace IgniteExample
{
class Program
{
static CommandList commands = new CommandList
{
new Command
{
Name = "hello",
Description = "Says hello",
Args = new CommandArgs
{
new CommandArg
{
Tag = "name",
InputFormat = "user name",
Description = "(string) The name used when saying hello",
Required = false,
}
},
Function = args =>
{
string name = CLI.String(args, "name");
CLI.Out($"Hello, {(String.IsNullOrEmpty(name) ? "World" : name)}!");
}
},
};
static void Main(string[] args)
{
CLI.Start(commands);
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 is compatible. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
-
.NETCoreApp 2.0
- No dependencies.
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 |
---|