Skip to content

mrploch/ploch-commandline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ploch CommandLine Applications

Overview

Ploch CommandLine Applications provides useful extensions to the CommandLineUtils library.

Features:

  • Preconfigured Dependency Injection
  • Preconfigured Microsoft Extensions Configuration
  • Simple, single-line, building of a configured and executable app
  • Interfaces for building commands
  • Simplified configuration for verbs (commands), including nested verbs
  • Streamlined configuration for
    • Autofac
    • Serilog

Quick Start

  1. Create a console application project

  2. Create a command class which includes executable code and commandline options:

using McMaster.Extensions.CommandLineUtils;
using Ploch.Common.CommandLine;

[Command(Name = "command1")]
public class RootCommand1(ISomeInterface dependency)
{
    [Option]
    public bool Verbose { get; set; }
    
    [Option]
    public string? Colour { get; set; }
    
    // Inferred type = MultipleValues
    // Defined names = "-N"
    public void OnExecute()
    {       
        Console.WriteLine($"Command1 executed");
    }
}
  1. Update the Program.cs file:
using McMaster.Extensions.CommandLineUtils;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Ploch.Common.CommandLine;
using Ploch.Common.CommandLine.Autofac;

// Demonstrates verbs with verbs using commands
await AppBuilder.CreateDefault(cfg => cfg.AddJsonFile("appsettings.json"))
    .Configure(container =>
    {
        // Add services
        container.ServiceCollection.AddSingleton<RootCommand1>()
                                   .AddSingleton<ISomeInterface, SomeClass>();

        container.Application.Command<RootCommand1>();
    })
    .Build()
    .ExecuteAsync(args);
  1. Run:
myapp.exe --help
myapp.exe command1 --verbose --colour Pink

About

Build advanced console applications with ease

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors