Isop 4.0.0-RC-1

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

// Install Isop as a Cake Tool
#tool nuget:?package=Isop&version=4.0.0-RC-1&prerelease

Isop Build Status Build status

The name

Isop is the swedish name for hyssop. Like any spice it is intended to give flavor to the development of command line apps in .net.

Goal

The goal is to be able to write code like:

someprogram.exe My Action --argument value

Or if you prefer:

someprogram.exe My Action /argument value

Isop will also figure out what you mean if you write with an equals sign between argument and value:

someprogram.exe My Action --argument=value

Or if you want to write it shorter you can skip the argument name:

someprogram.exe My Action value

So that the class with the name My or MyController and the method with the name Action gets invoked.

This library is intended to be like chocolate pudding mix. Not something that will replace your dinner, but rather something easy to make for dessert. A way of helping you build for instance the essential administrative apps. It's not a replacement for baking cake (building a full blown administrative interface in html).

When to use Isop

  • Early in your development life cycle (before having tools around for your business app)
  • You want an exe with many different commands organized into categories (here called controllers)

When not to use Isop

  • When your exe only has one command, then a simpler library like ndesc options is preferable.
  • You do not want any magic. Isop tries to help you with binding arguments to method arguments.
  • When you have a micro service solution together with some other authentication mechanism you can use Swagger to fill the same role.

License

MIT License

Nuget packages

Isop

Example

Having your own Main

You're hooking it up by writing something like:

static Task Main(string[] args)=>
    AppHostBuilder.Create()
       .Recognize(typeof(CustomerController))
       .BuildAppHost()
       .Parse(args)
       .TryInvokeAsync();

Where your controller looks something like this:

public class MyController
{
    private readonly CustomerRepository _repository;
    public MyController()
    {
        _repository = new CustomerRepository();
    }
    public IEnumerable<string> Add(string name)
    {
        yield return "Starting to insert customer";
        _repository.Insert( new Customer{ Name = name } );
        yield return "Customer inserted";  
    }
}

When invoked it will output two lines to the command prompt, the yielded lines above.

Handling errors and unrecognized parameters

class Program
{
    static async Task<int> Main(string[] args)
    {
        var appHost = AppHostBuilder
            .Create(new AppHostConfiguration
            {
                CultureInfo = CultureInfo.GetCultureInfo("sv-SE")
            })
            .Recognize(typeof(CustomerController))
            .BuildAppHost();
        try
        {
            var parsedMethod = appHost.Parse(args);
            if (parsedMethod.Unrecognized.Count != 0)//Warning:
            {
                await Console.Error.WriteLineAsync($@"Unrecognized arguments: 
    {string.Join(",", parsedMethod.Unrecognized.Select(arg => arg.Value).ToArray())}");
                return 1;
            }
            else
            {
                await parsedMethod.InvokeAsync(Console.Out);
                return 0;
            }
        }
        catch (TypeConversionFailedException ex)
        {
            await Console.Error.WriteLineAsync(
                $"Could not convert argument {ex.Argument} with value {ex.Value} to type {ex.TargetType}");
            if (null != ex.InnerException)
            {
                await Console.Error.WriteLineAsync("Inner exception: ");
                await Console.Error.WriteLineAsync(ex.InnerException.Message);
            }
            return 9;
        }
        catch (MissingArgumentException ex)
        {
            await Console.Out.WriteLineAsync($"Missing argument(s): {string.Join(", ", ex.Arguments).ToArray()}");
            await Console.Out.WriteLineAsync(await appHost.HelpAsync());
            return 10;
        }
    }
}

Why all this code? Mostly it's because I want the programmer to be able to have as much freedom as possible to handle errors and show error messages as he/she sees fit.

Alternative

If you want to have something simpler for simple command line applications then I would recommend using ndesc options or commandline or perhaps .net command-line-api.

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 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. 
.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.

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
4.0.0-RC-1 113 6/9/2024
3.0.2 1,375 7/13/2019
3.0.1 3,437 11/28/2018
3.0.0 1,696 11/11/2018
2.0.5 6,921 3/7/2015
2.0.1 1,812 2/1/2015
2.0.0 1,755 1/18/2015
1.1.0 1,805 9/16/2014
1.0.3 1,910 9/28/2013
1.0.2 1,822 9/21/2013
1.0.1 1,994 4/25/2013
1.0.0 1,860 3/14/2013