ConController 1.0.1

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

// Install ConController as a Cake Tool
#tool nuget:?package=ConController&version=1.0.1

ConController

Controller library for console applications. You can place the controllers in multiple files / classes, which is ideal for bigger projects. Parameters are converted automatically to the proper types.

Notes:

  • As you'll see in the next examples, the first operand tells, which method to call:
    • [controller name]/[entry point name]
  • Each method has to be static, but you can freely choose between sync and async modes of operation.
  • All controller classes must extend the ControllerBase, because they are identified this way. (You don't have to implement any interface, no worries.)

NuGet package

Available at: https://www.nuget.org/packages/ConController

To include it in a .NET Core project:

$ dotnet add package ConController

Example 1: sync with obligatory parameters

[Controller(Name = "test", Description = "For development purposes")]
public class TestController : ControllerBase {
    [EntryPoint(Name = "mult", Description = "Multiply two numbers")]
    [Parameter(Name = "left", Optional = false, Description = "First number")]
    [Parameter(Name = "right", Optional = false, Description = "Second number")]
    public static void Multiply(double left, double right) {
        Console.WriteLine($"\n {left} x {right} = {left * right}\n");
    }
}
$ dotnet run test/mult left=34.5 right=2

34.5 x 2 = 69

You can use classic parameter syntax with double dash:

$ dotnet run test/mult --left=34.5 --right=2

34.5 x 2 = 69

Example 2: async with optional parameter

[Controller(Name = "test", Description = "For development purposes")]
public class TestController : ControllerBase {
    [EntryPoint(Name = "out", Description = "Output text")]
    [Parameter(Name = "text", Optional = false, Description = "Text to output")]
    [Parameter(Name = "repeat", Optional = true, Description = "How many times to repeat the text.")]
    public static async Task Output(string text, int repeat = 3) {
        for(int i = 0; i < repeat; i++) {
            await Console.Out.WriteLineAsync(text);
        }
    }
}
$ dotnet run test/out text="This is a text" fileName=output.txt

This is a text
This is a text
This is a text

You can use classic parameter syntax with double dash:

$ dotnet run test/out --text="This is a text" --fileName=output.txt

This is a text
This is a text
This is a text

Example entry point: Program.cs

using System;
using System.Threading;
using System.Globalization;
using System.Threading.Tasks;

namespace YourNameSpace {
    public class Program {
        public static async Task<int> Main(string[] args) {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            try {
                return await CLI.Run(args);
            } catch (CommandParserException ex) {
                Console.Error.WriteLine($"\nError: {ex.Message}\n");
                return 1;
            }
        }
    }
}

The error messages from CommandParserException are user-friendly. You can display them in themselves without the full stack.

TODO

  • Generate text documentation from the descriptions and argument types.
  • Add more XML docs to the methods
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.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.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
1.0.3 524 3/12/2020
1.0.2 499 1/22/2020
1.0.1 492 1/19/2020
1.0.0 492 1/19/2020