JM.CLImber 0.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package JM.CLImber --version 0.2.0
NuGet\Install-Package JM.CLImber -Version 0.2.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="JM.CLImber" Version="0.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JM.CLImber --version 0.2.0
#r "nuget: JM.CLImber, 0.2.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 JM.CLImber as a Cake Addin
#addin nuget:?package=JM.CLImber&version=0.2.0

// Install JM.CLImber as a Cake Tool
#tool nuget:?package=JM.CLImber&version=0.2.0

CLImber - A Command Line Interface Library

Introduction

CLImber is a .Net library aimed at offloading the work of setting up, documenting, and parsing command line arguments. CLImber should allow your code to be smaller and more concisely focused on the actual work at hand rather than the plumbing required to support a robust command line interface.

CLImber was motivated by writing argument parsing logic over and over again for small utility projects. The need was highlighted as the functional code in my projects was dwarfed by the code required to parse and handle more and more options.

Technologies

My goal with CLImber is to keep it as small and as portable as possible.

  • .NET Standard 2.0 & C# v7.3

That's it. There are no other libraries, dependencies, or technologies. It should be noted that CLImber does use reflection to do most of its work.

Setup

Search for JM.CLImber on NuGet and install as usual through your favorite package manager interface.

Use

CLImber defines 3 types of command line artifacts. These are inspired by the git command line, so we will use that as an example:

git checkout -b new_branch

checkout is a command. Commands are considered the primary element that actually does work. In this case we know that checkout is going to switch our working directory to another branch.

-b is an option. Options are used to modify the behavior of commands. -b is telling the checkout command to create a new branch

CLImber does not currently support options. It is included here to make the explanation complete and because it is a planned feature. More details will be provided as that feature nears completion.

new_branch is an argument. An argument provides additional information to the command so it can complete a task. This example is providing checkout with the name of the branch to create and then checkout.

Implementation

So how would you tell CLImber about a checkout command? CLImber uses reflection to examine your code and find classes and their members that you have designated as commands. You have to provide the command string when you decorate your class with the CommandClass attribute.

using CLImber;

namespace CLImber.Example
{
    [CommandClass("checkout")]
    public class CheckoutCommand
    {
        [CommandHandler]
        public void Checkout(string branchName)
        {
            ///Do the actual work here.
        }
    }
}

CLImber can then be invoked at your Main method:

static void Main(string[] args)
{
    (new CLIHandler()).Handle(args);
}

CLImber then examines the assembly to find the CommandClass class with the correct command string. It then finds the methods in that class that have been decorated with the CommandHandler attribute. If there are multiple then CLImber will pick the method that has the correct number of arguments. If any arguments require conversion CLImber will convert them and then construct the class and invoke the method, passing all arguments. This means that your methods can use strongly typed arguments instead of having to convert from strings as the first step.

With simple attributes and a little bit of reflection CLImber handles the discovery of commands and the methods to call to make sure everything is handled correctly. Your project code remains cleaner and focused on achieving the operational goals.

The list of type converters that CLImber is aware of can be extended so you can deal with any classes that are particular to your libraries. CLImber even supports rudimentary dependency injection so you don't have to have a bunch of global resources in your project either.

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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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.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
1.0.1 191 12/11/2023
1.0.0 103 12/10/2023
0.6.0 416 9/8/2021
0.5.3 290 3/29/2021
0.5.1 291 3/29/2021
0.5.0 357 3/27/2021
0.4.0 323 3/13/2021
0.3.0 329 3/3/2021
0.2.0 310 2/20/2021

Initial release. Supports commands, arguments, and usage help.