PatcatGames.CommandLineUtilities 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package PatcatGames.CommandLineUtilities --version 1.0.1
                    
NuGet\Install-Package PatcatGames.CommandLineUtilities -Version 1.0.1
                    
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="PatcatGames.CommandLineUtilities" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PatcatGames.CommandLineUtilities" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="PatcatGames.CommandLineUtilities" />
                    
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 PatcatGames.CommandLineUtilities --version 1.0.1
                    
#r "nuget: PatcatGames.CommandLineUtilities, 1.0.1"
                    
#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 PatcatGames.CommandLineUtilities@1.0.1
                    
#: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=PatcatGames.CommandLineUtilities&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=PatcatGames.CommandLineUtilities&version=1.0.1
                    
Install as a Cake Tool

License NuGet

Patcat Command Line Utilities

Extensions and Attributes for System.CommandLine for ease of use, originally created for PatcatCLI & PatcatDB.

⚠️ Limitations

  • This library does NOT support AoT compilation due to its use of Reflection (future support planned)
  • This library does not support array options yet

Features

Extension Methods

AddCommandFromMethod
var rootCommand = new RootCommand(description: @"This is the root level command description.");
rootCommand.AddCommandFromMethod(typeof(Program).GetMethod(nameof(MyCommand)));
ConfigureFromMethod
var rootCommand = new RootCommand(description: @"This is the root level command description.");
var myCommand = new Command("my-command");
myCommand.ConfigureFromMethod(typeof(Program).GetMethod(nameof(MyCommand)));
rootCommand.AddCommand(myCommand);

Attributes

Attribute Description
[Alias(string)] Defines alternate (usually shorter) names for options. Multiple aliases allowed. Only works on [Option] parameters.
[Description(string)] Sets description text for methods and parameters in CLI help.
[Option] Marks a parameter as optional (must have default value).
[PrettyName(string)] Provides human-readable names for parameters in help pages (doesn't affect functionality).

Complete Example

using System.CommandLine;
using Patcat.CommandLineUtils;

class Program
{
    static Task<int> Main(string[] args)
    {
        var rootCommand = new RootCommand(description: @"This is the root level command description.");
        rootCommand.AddCommandFromMethod(typeof(Program).GetMethod(nameof(MyCommand)));
        return rootCommand.InvokeAsync(args);
    }
    
    [Description("This is the description of my-command")]
    public static void MyCommand(
        [Description("The first argument.")] string firstArgument,
        [Description("The second argument, but this one is optional.")] string secondArgument = "default!",
        [Option][Alias("-o1")][PrettyName("Option 1 Pretty Name")] string optionOne = "1",
        [Option][Alias("-o2")][Alias("-2")][PrettyName("Option 2 Pretty Name")] string optionTwo = "2",
        [Option][Alias("-y")][Description("Skips confirmations.")] bool skipConfirmations = false
    )
    {
        Console.WriteLine($"firstArgument = {firstArgument}");
        Console.WriteLine($"secondArgument = {secondArgument}");
        Console.WriteLine($"optionOne = {optionOne}");
        Console.WriteLine($"optionTwo = {optionTwo}");
        Console.WriteLine($"skipConfirmations = {skipConfirmations}");
    }
}

Help Output Examples

Root command help:

Description:
  This is the root level command description.

Usage:
  PatcatDB.CLI [command] [options]

Options:
  --version       Show version information
  -?, -h, --help  Show help and usage information

Commands:
  my-command <FirstArgument> <SecondArgument>  This is the description of my-command [default: default!]

Command-specific help:

Description:
  Publishes a PatcatDB module to a database.

Usage:
  PatcatDB.CLI publish <FirstArgument> [<SecondArgument>] [options]

Arguments:
  <FirstArgument>  The first argument.
  <SecondArgument>  The second argument, but this one is optional. [default: default!]

Options:
  --optionOne, -o1 <Option 1 Pretty Name>  [default: 1]
  --optionTwo, -o2, -2 <Option 2>  [default: 2]
  -y, --skip-confirmations         Skips confirmations. [default: False]
  -?, -h, --help                   Show help and usage information

Setting Up as a .NET Tool

  1. Add to your .csproj file:
<PackAsTool>true</PackAsTool>
<ToolCommandName>command-name</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>

Example project file:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net8.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <PackAsTool>true</PackAsTool>
        <ToolCommandName>command-name</ToolCommandName>
        <PackageOutputPath>./nupkg</PackageOutputPath>
        <Version>1.0.0</Version>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="System.CommandLine" Version="2.*" />
        <ProjectReference Include="PatcatGames.CommandLineUtilities" Version="1.*" />
    </ItemGroup>
</Project>
  1. Pack and install:
dotnet pack
dotnet tool install --global --add-source ./nupkg ProjectName

License

MIT License

Copyright (c) 2025 Patcat Games LTD

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  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.

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.3 1,053 5/21/2025
1.0.2 163 5/8/2025
1.0.1 152 5/8/2025
1.0.0 150 5/8/2025