This repository has been archived on 2023-02-02. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
Dylan R. E. Moonfire bb0dcd0d86 refactor!: moved table services into a dedicated assembly 2022-04-02 19:15:31 -05:00
.config build: switching setup for calculating Git versions 2022-04-02 19:14:26 -05:00
scripts refactor!: moved table services into a dedicated assembly 2022-04-02 19:15:31 -05:00
src refactor!: moved table services into a dedicated assembly 2022-04-02 19:15:31 -05:00
tests refactor!: moved table services into a dedicated assembly 2022-04-02 19:15:31 -05:00
.editorconfig refactor!: moved table services into a dedicated assembly 2022-04-02 19:15:31 -05:00
.envrc ci: switching to a Nix-based build environment 2021-11-30 20:12:29 -06:00
.gitignore build: adding lefthook for hook management 2022-04-02 19:15:30 -05:00
.gitlab-ci.yml build: adding some automatic formatting on commits 2022-04-02 19:15:31 -05:00
.prettierignore refactor!: moved table services into a dedicated assembly 2022-04-02 19:15:31 -05:00
LICENSE.md refactor!: switched from MIT to AGPL-3.0 license 2022-04-02 19:14:26 -05:00
MfGames.ToolBuilder.sln refactor!: moved table services into a dedicated assembly 2022-04-02 19:15:31 -05:00
MfGames.ToolBuilder.sln.DotSettings feat: initial commit 2021-09-10 12:33:42 -05:00
NuGet.Config feat: initial commit 2021-09-10 12:33:42 -05:00
README.md refactor!: moved table services into a dedicated assembly 2022-04-02 19:15:31 -05:00
flake.lock feat!: refactored to handle updates to System.CommandLine 2022-04-02 19:14:25 -05:00
flake.nix build: adding some automatic formatting on commits 2022-04-02 19:15:31 -05:00
lefthook.yml build: adding some automatic formatting on commits 2022-04-02 19:15:31 -05:00

README.md

MfGames.ToolBuilder

An opinionated library for easily creating command-line tools in C#.

MfGames.ToolBuilder is a library to encapsulate the setup and running of tools, CLI components arranged with verbs (like git). It includes some opinionated decisions on default setup.

Building

To make sure the environment is correctly set up for build:

./scripts/setup.sh

To build the project:

./scripts/build.sh

To test the project:

./scripts/test.sh

Commands

This library is built on top of System.CommandLine and .NET 6 generic hosting. The commands are combined together using dependency injection (see below) which allows for them to be included as parameters for the constructor or dynamically discovered.

All commands are assumed to be asynchronous and include a cancellation token in their calls.

System.CommandLine was chosen because it allows for composition of features instead on needing inheritance to give a tool the ability to render a table or handle additional features.

Autofac

While most libraries should only use the included service provider infrastructure with the base library, this tool sets up Autofac to handle services. This allows for both service provider usage (via ConfigureServices) and Autofac (via ConfigureContainer).

Autofac was chosen because of a number of quality of life features and personal preferences of the developer. A tool can easily ignore that functionality in favor of using only IServiceProvider.

Serilog

Likewise, tools are set up to use Serilog for logging instead of the built-in logging code. However, both are served by Serilog so ILoggerFactory<T> can be used.

Like Autofac, Serilog was given because of the variety of sinks, certain quality of life, but also the ability to log more detailed objects. It also produces some coloring to log details based on data types.

To use the Serilog functionality with ILoggerFactory, objects needed to be included as parameters instead of inlined with string interpolation.