Isop 4.0.0-RC-1
dotnet add package Isop --version 4.0.0-RC-1
NuGet\Install-Package Isop -Version 4.0.0-RC-1
<PackageReference Include="Isop" Version="4.0.0-RC-1" />
paket add Isop --version 4.0.0-RC-1
#r "nuget: Isop, 4.0.0-RC-1"
// 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
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
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 | Versions 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. |
-
.NETStandard 2.0
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.2)
- System.ComponentModel.Annotations (>= 5.0.0)
-
net8.0
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.2)
- System.ComponentModel.Annotations (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.