AbroadConcepts.CommandLine 9.0.7

dotnet add package AbroadConcepts.CommandLine --version 9.0.7
                    
NuGet\Install-Package AbroadConcepts.CommandLine -Version 9.0.7
                    
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="AbroadConcepts.CommandLine" Version="9.0.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AbroadConcepts.CommandLine" Version="9.0.7" />
                    
Directory.Packages.props
<PackageReference Include="AbroadConcepts.CommandLine" />
                    
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 AbroadConcepts.CommandLine --version 9.0.7
                    
#r "nuget: AbroadConcepts.CommandLine, 9.0.7"
                    
#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 AbroadConcepts.CommandLine@9.0.7
                    
#: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=AbroadConcepts.CommandLine&version=9.0.7
                    
Install as a Cake Addin
#tool nuget:?package=AbroadConcepts.CommandLine&version=9.0.7
                    
Install as a Cake Tool

AbroadConcepts.CommandLine

This package allows for easy parameter parsing into an application. It works by registering various class containers that get loaded when Parse is called.

Description

The current limitation is this class does not support requirement for all parameters in a container to be set before moving to optional parameters. In sample below if "hello -o test" is the parameters, then mainArg.FirstParameter is set to "hello" and optionalArg.FirstOptionArg is set to "test". Note there is no error given for mainArg.SecondParameter not being passed in.

Properties

        public string Message {get; set;}        // Set to any error message if Parse fails. 

        public List<string> Options {get; set;}  // List of Options that where set.   The order of the list
                                                 // determines the order of parameters parsed.

Method

        public bool Parse (IArgument setting)    // Parses the command line into arguments
        public bool Parse (IArgument setting, IEnumerable<ICommandArgument> arguments)    // Parses the command line into arguments

                                                                                       // setting is the container class for expected parameters.

        public T GetNextArgument<T>() where T : IArgument   // Returns the next argument

Example Code C#

The following sample demonstrates usage:

defining class containers:

public class MainArg : IArgument
{
    public string FirstParameter { get; set; } = string.Empty;
    public int SecondParameter { get; set; } = 0;
}

public class OptionalArg : IArgument
{
    public string FirstOptionArg { get; set; } = string.Empty;
}

public class SettingOptionalArg : ICommandArgument
{
    public string CommandOption => "-a";

    public Type ArgumentType => typeof(OptionalArg);

}


In Program.cs declare these containers and register the optional parameter to

using AbroadConcepts.CommandLine;

MainArg mainArg = new();
var argSettings = [{new SettingsOptionalArg()}];
var cmdLine = new CommandArguements(args);
if (cmdLine.Parse(mainArg, argSettings))
{
    // at this point mainArg will be set as well as any values parsed for optional arguments.
    // cmdLine.Options will be a list with entry of "-o".
    var optionalArg = cmdLine.GetNextArgument<OptionalArg> ();
    if (optionalArg.FirstOptionArg  == "key")
    {
        // do something unique with option being specified. 
    }
}
else
{
    Console.WriteLine ($"Message is {cmdLine.Message}")
}
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.
  • net9.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
9.0.7 220 5/27/2025
9.0.6 195 5/7/2025
9.0.5 193 5/7/2025
9.0.4 201 5/6/2025
9.0.3 302 4/27/2025 9.0.3 is deprecated.
9.0.2 281 4/27/2025 9.0.2 is deprecated.
9.0.1 273 4/27/2025 9.0.1 is deprecated.
9.0.0 250 2/6/2025 9.0.0 is deprecated.
1.0.1 261 12/30/2024 1.0.1 is deprecated.
1.0.0 166 12/30/2024 1.0.0 is deprecated.