ConsoleAuto 1.0.73

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

// Install ConsoleAuto as a Cake Tool
#tool nuget:?package=ConsoleAuto&version=1.0.73

ConsoleAuto

Library that automates console argument parsing and script automation.

.NET Core Nuget Nuget

Why use this parsing library?

Command line parsing is something that usually is approached in this way: you define argument syntax, you parse it using command line parser library and then you use the parameter into the applciation. This approach need many steps and it is hard to mantain. This library collapse all steps in just one: describe your method.

You just need to declare a method somewhere and add an annotation on it to let things goes in automatic. Another interesting scenario is the execution of multiple commands by config yaml file (similar to the docker files mechanism).

See the exampe to learn how this will simplify your console application.

Install-Package ConsoleAuto

Features

  • automatic info definition
  • interactive mode
  • automatic parameter mapping
  • use dependency injection
  • can run a sequence of command allowing command scripting

How it work

Simple ussage

class Program
{
    static void Main(string[] args)
    {
        ConsoleAuto.Config(args)
            .LoadCommands()
            .Run();
    }

    [ConsoleCommand]
    public void MyMethod(string inputOne, int inputTwo)
    {
        //do stuff here
	}
}

this program will be usable running:

Myprogram MyMethod --inputOne xxxx --inputTwo 23

Each method annotated by ConsoleCommand is available for being invoked. Method can be in classes ouside the program file, static or not. Non static classes are created using DI and can receive dependencies in the costructor. The default command is the info one, that shows usage information (generated automatically from command definitions)

public class IOCommands
{
    public ConsoleService consoleService;
    public IOCommands(ConsoleService consoleService)
    {
        this.consoleService = consoleService;
    }

    [ConsoleCommand(isPublic: false,info:"provide  this description")]
    public void WriteText(string text, bool newline)
    {
        //do stuff here 
    }
}

Advanced usage

  ConsoleAuto.Config(args, servicecollection)// pass servicecollection to use the same container of main application
    .LoadCommands() //Load all commands from entry assembly + base commands
    .LoadCommands(assembly) //Load from a custom command
    .LoadFromType(typeof(MyCommand)) //load a single command
    .Register<MyService>() // add a service di di container used in my commands
    .Register<IMyService2>(new Service2()) // add a service di di container used in my commands, with a custom implementation
    .Default("MyDefaultCommand") //specify the default action if app starts without any command
    .Configure(config => { 
        //hack the config here
    })
    .Run();
Configuration options
Method Note
Config inf service collection is null, creates an internal container for DI
LoadCommand Load all commands from entry assembly + base commands, basing on annotation
Register register a dependency for commands. If you are using DI on main application the dependency will be added on main DI container also. If you are using DI and you already added dependency you do not need to register.
Configure this exposes the resulting configuration. Use at your risk.
Run Execute the program
Default the command executed if no command is specified. default value is the info command.
Command options
Parameter Note
Name the name of the command (will be used for launching it from console)
IsPublic if true it is visible on console info
Mode Can be on-demand,
Order the execution order for non on-demand, BeforeCommand, or AfterCommand. The on deamand options is the default one and probably what you usually whant. The commands do nothing unless the user run it from command line. After and Before mode run the command anytime you run an ondemand command. For example, the "welcome" or "pres a key to close" are before and after event.

Programmatic usage usage

This tool can be used to execute a set of action. In this mode you can define many atomic commands and then define the sequence using an external file.

The settings file MyScript.yaml

Commands:
    welcome_step1:
       Action: welcome
       Desctiption: This is the line of text that will shown first 
       Args:
            header: my text (first line)
    welcome_step2:
       Action: welcome
       Desctiption:  In this example we do it twice, to prove we can execute commands multiple times with different args.
       Args:
           header: my text (second line)
    main_step:
       Action: CommandOne
       Desctiption: This is a custom command that diplay the test. Yes, another dummy thing.
       Args:
         text: I'm the central command output!
State:
   text: myglobal



MyExec.exe  exec MyScript.yaml

TODOS

  • interactive mode
  • overload for removing default commands/Disabling

LICENSE

This library is released under the term of MIT License.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Icons made by Eucalyp from Flaticon

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.

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.73 526 5/9/2020
1.0.72 578 5/9/2020
1.0.71 582 5/9/2020
1.0.68 551 5/9/2020
1.0.67 560 5/9/2020
1.0.66 585 5/9/2020
1.0.65 576 5/9/2020