NetLah.Extensions.CommandLineUtils 0.1.0-a1.2

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
This is a prerelease version of NetLah.Extensions.CommandLineUtils.
dotnet add package NetLah.Extensions.CommandLineUtils --version 0.1.0-a1.2
NuGet\Install-Package NetLah.Extensions.CommandLineUtils -Version 0.1.0-a1.2
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="NetLah.Extensions.CommandLineUtils" Version="0.1.0-a1.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetLah.Extensions.CommandLineUtils --version 0.1.0-a1.2
#r "nuget: NetLah.Extensions.CommandLineUtils, 0.1.0-a1.2"
#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 NetLah.Extensions.CommandLineUtils as a Cake Addin
#addin nuget:?package=NetLah.Extensions.CommandLineUtils&version=0.1.0-a1.2&prerelease

// Install NetLah.Extensions.CommandLineUtils as a Cake Tool
#tool nuget:?package=NetLah.Extensions.CommandLineUtils&version=0.1.0-a1.2&prerelease

NetLah.Extensions.CommandLineUtils - .NET Library

NetLah.Extensions.CommandLineUtils Command line parsing for .NET.

Nuget package

NuGet

Build Status

.NET

Getting started

1. Add/Update PackageReference to web .csproj

<ItemGroup>
  <PackageReference Include="NetLah.Extensions.CommandLineUtils" />
</ItemGroup>

2. Sample Command Line Application

CommandLineApplication commandLineApplication =
    new(throwOnUnexpectedArg: false)
    {
        Name = "SampleCommandLine.exe",
        FullName = "SampleCommandLine: greeting a fullname"
    };

CommandArgument? names = null;

commandLineApplication.Command("hello",
    (target) =>
    {
        target.FullName = "Greeting a fullname";
        target.Description = "The hello command";
        target.ShortVersionGetter = GetShortVersion;
        target.LongVersionGetter = GetLongVersion;

        names = target.Argument(
            "fullname",
            "Enter the full name of the person to be greeted.",
            multipleValues: true);

        target.HelpOption("-? | -h | --help");

        target.OnExecute(() =>
        {
            if (names?.Values.Any() == true)
            {
                Greet(names.Values);
            }
            else
            {
                // show help if the required argument is missing
                commandLineApplication.ShowHelp();
            }
            return 0;
        });
    });

commandLineApplication.HelpOption("-? | -h | --help");
commandLineApplication.VersionOption("--version", GetShortVersion, GetLongVersion);

commandLineApplication.OnExecute(() =>
{
    // show help if root command
    commandLineApplication.ShowHelp();
    return 0;
});

commandLineApplication.Execute(args);

static void Greet(IEnumerable<string> values) => Console.WriteLine($"Hello {string.Join(" ", values)}!");

static string GetLongVersion() => "1.2.3";

static string GetShortVersion() => "v1.2.3+456abcd";

Play around

1. Get help on root

To know the available commands and options SampleCommandLine.exe --help

SampleCommandLine: greeting a fullname v1.2.3+456abcd

Usage: SampleCommandLine.exe [options] [command]

Options:
  -? | -h | --help  Show help information
  --version         Show version information

Commands:
  hello  The hello command

Use "SampleCommandLine.exe [command] --help" for more information about a command.

2. Get help on hello command

To know the available arguments and options of a command SampleCommandLine.exe hello --help

Greeting a fullname v1.2.3+456abcd

Usage: SampleCommandLine.exe hello [arguments] [options]

Arguments:
  fullname  Enter the full name of the person to be greeted.

Options:
  -? | -h | --help  Show help information

3. Greeting a fullname

Command line SampleCommandLine.exe hello John Doe

Hello John Doe!

4. Check version

Command line SampleCommandLine.exe --version

SampleCommandLine: greeting a fullname
1.2.3

Project origin and status

This repos a fork of Microsoft.Extensions.CommandLineUtils. Microsoft announces discontinue support the library. You may check this repos if prefer the more enrich features.

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)
Additional computed target framework(s)
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
0.1.0-a1.2 436 10/8/2022