CommandAppInterface 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package CommandAppInterface --version 1.0.0
                    
NuGet\Install-Package CommandAppInterface -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CommandAppInterface" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CommandAppInterface" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="CommandAppInterface" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CommandAppInterface --version 1.0.0
                    
#r "nuget: CommandAppInterface, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CommandAppInterface@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CommandAppInterface&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=CommandAppInterface&version=1.0.0
                    
Install as a Cake Tool

Command App Interface

This is a library for easy command interface making (actualy I used something like this in my other projects, but I tired of always typing if/else):<br> изображение (you can see this example in CAIExamples folder)

Usage:

First you need to use CAI namespace and create CAI instance:

AppInterface interface = new(caiName: "example", isCatchExceptions: true);

If you want to handle exceptions yourself, set isCatchExceptions false. Next to create a command, use AppInterface.AddCommand method:

interface.AddCommand(new Command("command_name", "this is a command without parameters", DoSomeDealMethod, "this is text about how to use this command);

interface.AddCommand<int>(new Command("command_with_int_parameter", "this command expects an int parameter after command name", MethodWithIntArgument, "usage: \"command_with_int_parameter 42\""));

Now commands support up to 4 various parameters. Each parameters implements IParsable.<br> In the command constructor, the command handler method is assigned. It must have the same number of parameters and the same types as those specified in the command generics

To start interface, run AppInterface.Start() method:

interface.Start();

The whole code looks like this:

...
AppInterface interface = new(caiName: "example", isCatchExceptions: true);

interface.AddCommand(new Command("command_name", "this is a command without parameters", DoSomeDealMethod, "this is text about how to use this command);
interface.AddCommand<int>(new Command("command_with_int_parameter", "this command expects an int parameter after command name", MethodWithIntArgument, "usage: \"command_with_int_parameter 42\""));

interface.Start();
...

Also CAI contains built-in commands: изображение

You can run one CAI inside other. In this case when you type quit, you will exit from internal CAI and continue working in external CAI: изображение

Native AOT:

CAI uses Spectre.Console (Not Spectre.Console.Cli!!!), as stated in https://spectreconsole.net/best-practices, Spectre.Console supports Native AOT.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.4.0 561 7/23/2025
1.3.1 131 4/19/2025
1.3.0 138 4/12/2025
1.2.0 119 3/14/2025
1.1.0 248 3/6/2025
1.0.1 235 3/3/2025
1.0.0 131 3/2/2025