CypherPotato.CommandLine 1.0.0

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

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

CommandLine

This tiny library has an purpose to extract values from the command line. It is not capable of interpreting subcommands and does not use reflection to extract data. It is so small that it contains a class and that class contains 2 methods and 2 properties.

Consider this command line:

curl.exe -h "Content-Length: 0" -h "User-Agent: foo/1.0" -X POST https://example.com/posts

You can parse it and get each parameter with:

static void Main(string[] args)
{
    var parser = new CommandLine.CommandLineParser(args, StringComparison.InvariantCulture);
    
    string[] headers = parser.GetValues("header", 'h').ToArray();
    string? method = parser.GetValue("method", 'X');
    string? url = parser.GetRemainder()?.LastOrDefault();
        
    Console.WriteLine("Headers  = {0}", string.Join(", ", headers));
    Console.WriteLine("Method   = {0}", method);
    Console.WriteLine("Url      = {0}", url);
}

Getting multiple values

example.exe -p param1 param2 param3 -d "another command" --parameter param4 --foobar
static void Main(string[] args)
{
    var parser = new CommandLine.CommandLineParser(args);
    
    string[] headers = parser.GetValues("parameter", 'p').ToArray();
    // ["param1", "param2", "param3", "param4"]
}

Getting a single value

example.exe -d "command" --foo "hello"
static void Main(string[] args)
{
    var parser = new CommandLine.CommandLineParser(args);
    
    string? d = parser.GetValue("directive", 'd'); // "command"
    string? f = parser.GetValue("foo", 'f'); // "hello"
    string? x = parser.GetValue("empty"); // null
}

Check if has switch

example.exe --verbose
static void Main(string[] args)
{
    var parser = new CommandLine.CommandLineParser(args);
    
    bool verbose = parser.IsDefined("verbose"); // short-terms are optional for all methods
}

Get parameterless values

example.exe build --language "csharp" -r "System.dll" program.cs lib.cs --out item.cs foobar
static void Main(string[] args)
{
    var parser = new CommandLine.CommandLineParser(args);
    
    string[] remainder = parser.GetRemainder().ToArray();
    // ["build", "program.cs", "lib.cs", "foobar"]
}

And that's all this lib can do.

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.
  • .NETStandard 2.1

    • 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 91 4/11/2024