JsonCommandLine 1.0.0

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

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

<div align="center"> <h1>JsonCommandLine</h1> </div>

Provides a simple and easy API to pass JSON command line arguments. and yes, it can parse arguments which are generated like so too!

JsonCommandLine library works little bit differently compared to other CommandLine parsers. Every argument must have a base Command keyword. It can have multiple parameters. Command keyword is used to identify the argument and the parameters are used to pass values with reference to command keyword. Parameters are stored in Dictionary<string,string>() while BaseArgument is a single string

Sample usage

static void Main(string[] args) {
			// parsing args
			using (CommandLineParser parser = new CommandLineParser(Environment.CommandLine)) {
				// check if this args contain values are generated by JsonCommandLine
				// if its not, we can't parse it
				if (!parser.IsJsonType) {
					return;
				}

				// parses the arguments
				var arguments = parser.Parse();

				if (arguments.ArgumentsExist) {
					foreach(var arg in arguments.ArgumentCollection) {
						// the base command
						Console.WriteLine(arg.BaseCommand);

						foreach(var param in arg.Parameters) {
							// parameters of the above base command
							Console.WriteLine($"{param.Key} -> {param.Value}");
						}
					}
				}
			}

			// generating args
			// initiate an argument with base command
			CommandLineArgument argument = new CommandLineArgument("update");

			// add parameters to the base command
			argument.TryAddParameter("enableTrace", "false");
			argument.TryAddParameter("generateBackup", "true");

			// generate builder to chain multiple arguments into single instance
			argument.GenerateArgumentBuilder()
				// add another argument
				.Add(new CommandLineArgument("restart", new Dictionary<string, string>() {
					{"path", "foo/bar/word.exe" }
				}))
				// maybe add another ?
				.Add(new CommandLineArgument("shutdownTimed", new Dictionary<string, string>() {
					{"delaySeconds", "10" }
				}))
				// either build as Arguments object which contains all chained command line arguments
				// .BuildAsArgument();
				// or
				// as resultant command line argument string which will be passed to the next process as args.
				// .Build();
				.Build()

				// we call AsArgument() on Arguments object to turn the chained arguments into resultant args string
				// above BuildAsArgument() function does the same, just that it directly converts it to string args.
				.AsArgument();
		}
  • Dependencies
    • Newtonsoft.Json (>= 12.0.3)
Product 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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.0.0 512 8/9/2020