StringCommandParser 1.0.0

dotnet add package StringCommandParser --version 1.0.0
NuGet\Install-Package StringCommandParser -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="StringCommandParser" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add StringCommandParser --version 1.0.0
#r "nuget: StringCommandParser, 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.
// Install StringCommandParser as a Cake Addin
#addin nuget:?package=StringCommandParser&version=1.0.0

// Install StringCommandParser as a Cake Tool
#tool nuget:?package=StringCommandParser&version=1.0.0

StringCommandParser for .Net 5.0

The StringCommandParser library gives an easy way to define verbs and methods for use in any situations where a string args situation for example Discord, Teams or Slack bot where you are taking user input and running a method based on the input.

Install-Package StringCommandParser

Features

  • No dependencies
  • Automatic help text generation
  • Compatible with .Net 5.0

Quick start

First create or inject an instance of Parser:

IParser parser = new Parser

Define the verbs and methods you want to be accessible from the parser:

[Verb(Verb:"debug", HelpText:"Contains debugging methods")]
public class Debug {
	
	[Command(Method:"env",HelpText:"Returns environment information")]
	public void PrintEnv(){
		//Do something
	}
	
	[Command(Method:"echo",HelpText:"Returns the parameter")]
	public string PrintEnv(string echoText){
		return echoText
	}
}

Split the input string and pass it into the parser:

var input = "debug env" // this will call the Debug.PrintEnv() method
var args = input.Split(" ");

var help = parser.ParseArgs<Debug>(args) //Multiple types can be provided here <T1,T2,T3...etc>
			.ExecuteMethod(x =>
            {
	        //Lambda is used here to allow for role processing etc, e.g:
		if(!isAdmin && x.Verb == "Admin") return false;
	            
                x.Method.Invoke(null, x.Args); //If the method isn't static, replace null with an instance of the class
                return true;
            })
            .CatchParseError(); // If the ParseArgs method fails to find a matching verb, command, or there's a parameter mismatch the help text will be returned by this method

The syntax of a parser command is:

<verb> <command> <arg1> <arg2> <arg3> etc 
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net5.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
1.0.0 309 7/1/2021