ManyConsole.Standard 2.0.0

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

// Install ManyConsole.Standard as a Cake Tool
#tool nuget:?package=ManyConsole.Standard&version=2.0.0                

ManyConsole

Available on Nuget: http://nuget.org/List/Packages/ManyConsole

Thanks to Daniel González for providing some additional documentation: http://dgondotnet.blogspot.dk/2013/08/my-last-console-application-manyconsole.html

Mono.Options (formerly NDesk.Options) is a great library for processing command-line parameters. ManyConsole extends Mono.Options to allow building console applications that support separate commands.

If you are not familiar with Mono.Options, you should start by using that: https://components.xamarin.com/gettingstarted/mono.options?version=5.3.0. Add ManyConsole when you feel the urge to differentiate commands (you'll still need the Mono.Options usage).

ManyConsole provides a console interface for the user to list available commands, call and get help for each.

To use ManyConsole:

Quick Start Guide

Run this from NuGet Package Management Console:

Install-Package ManyConsole

Drop this in to automatically load all of the commands that we'll create next:

public class Program
{
    public static int Main(string[] args)
    {
        var commands = GetCommands();

        return ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out);
    }

    public static IEnumerable<ConsoleCommand> GetCommands()
    {
        return ConsoleCommandDispatcher.FindCommandsInSameAssemblyAs(typeof(Program));
    }
}

Create a command with one optional, one required and a short and long description:

public class PrintFileCommand : ConsoleCommand
{
    private const int Success = 0;
    private const int Failure = 2;

    public string FileLocation { get; set; }
    public bool StripCommaCharacter { get; set; }

    public PrintFileCommand()
    {
        // Register the actual command with a simple (optional) description.
        IsCommand("PrintFile", "Quick print utility.");
            
        // Add a longer description for the help on that specific command.
        HasLongDescription("This can be used to quickly read a file's contents " +
        "while optionally stripping out the ',' character.");
            
        // Required options/flags, append '=' to obtain the required value.
        HasRequiredOption("f|file=", "The full path of the file.", p => FileLocation = p);

        // Optional options/flags, append ':' to obtain an optional value, or null if not specified.
        HasOption("s|strip:", "Strips ',' from the file before writing to output.",
            t => StripCommaCharacter = t == null ? true : Convert.ToBoolean(t));
    }

    public override int Run(string[] remainingArguments)
    {
        try
        {
            var fileContents = File.ReadAllText(FileLocation);

            if (StripCommaCharacter)
                fileContents = fileContents.Replace(",", string.Empty);

            Console.Out.WriteLine(fileContents);

            return Success;
        }
        catch (Exception ex)
        {
            Console.Error.WriteLine(ex.Message);
            Console.Error.WriteLine(ex.StackTrace);

            return Failure;
        }
    }
}

Ok, now when you run it, it should work:

>ManyConsoleDocumentation PrintFile -f "C:\HelloWorld.txt"

Extra parameters specified: C:\HelloWorld.txt

'PrintFile' - Quick print utility.

This can be used to quickly read a file's contents while optionally stripping out the ',' character.

Expected usage: ManyConsoleDocumentation.exe PrintFile <options>
<options> available:
  -f, --file                 The full path of the file.
  -s, --strip                Strips ',' from the file before writing to
                               output.

It doesn't work and thinks we specified an invalid parameter. This is because options that are followed by a parameter must have an '=' symbol, so update the two commands with f|file= and s|strip=, it should now work:

>ManyConsoleDocumentation PrintFile -f "C:\HelloWorld.txt"

Executing PrintFile (Quick print utility.):
    FileLocation : C:\HelloWorld.txt
    StripCommaCharacter : False

Hello, world!

>ManyConsoleDocumentation PrintFile -f "C:\HelloWorld.txt" -s true

Executing PrintFile (Quick print utility.):
    FileLocation : C:\HelloWorld.txt
    StripCommaCharacter : True

Hello world!

Now you can easily supply multiple commands with their own set of unique arguments:

public class EchoCommand : ConsoleCommand
{
    public string ToEcho { get; set; }

    public EchoCommand()
    {
        IsCommand("Echo", "Echo's text");
        HasRequiredOption("t|text=", "The text to echo back.", t => ToEcho = t);
    }

    public override int Run(string[] remainingArguments)
    {
        Console.Out.WriteLine(ToEcho);

        return 0;
    }
}

Here's how the help looks, plus help for our two commands:

>ManyConsoleDocumentation help

Available commands are:

    Echo        - Echo's text
    PrintFile   - Quick print utility.

    help <name> - For help with one of the above commands

>ManyConsoleDocumentation help PrintFile

'PrintFile' - Quick print utility.

This can be used to quickly read a file's contents while optionally stripping out the ',' character.

Expected usage: ManyConsoleDocumentation.exe PrintFile <options>
<options> available:
  -f, --file=VALUE           The full path of the file.
  -s, --strip=VALUE          Strips ',' from the file before writing to
                               output.

>ManyConsoleDocumentation help Echo

'Echo' - Echo's text

Expected usage: ManyConsoleDocumentation.exe Echo <options>
<options> available:
  -t, --text=VALUE           The text to echo back.
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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on ManyConsole.Standard:

Repository Stars
Neskol/MaichartConverter
A format converter for maimai related charts
Version Downloads Last updated
2.0.0 25,748 6/27/2019

Moved to .NET Standard 2.0