Cackle.ConsoleApp 1.0.1

This package has a SemVer 2.0.0 package version: 1.0.1+11.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Cackle.ConsoleApp --version 1.0.1
                    
NuGet\Install-Package Cackle.ConsoleApp -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="Cackle.ConsoleApp" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Cackle.ConsoleApp" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Cackle.ConsoleApp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Cackle.ConsoleApp --version 1.0.1
                    
#r "nuget: Cackle.ConsoleApp, 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.
#:package Cackle.ConsoleApp@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Cackle.ConsoleApp&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Cackle.ConsoleApp&version=1.0.1
                    
Install as a Cake Tool

GitHub last commit (branch) CodeFactor GitHub tag (with filter)

<img align="right" alt="Cackle Logo" height="128" width="128" src="https://github.com/mrUlrik/Cackle.ConsoleApp/blob/main/docs/images/package.png?raw=true" />

Cackle.ConsoleApp

A library that provides logging, dependency injection, command line parsing, and other small features in a simple package. This library is an amalgamation of excellent libraries I use frequently, knitted together in an easy to use package. My daily work life results in creating many console applications and recreating the wheel became extremely tiring.

This library utilizes and provides the following:

  • Ardalis.GuardGlauses
    • Basic predefined, guard clauses with simpler than home-brew expansion with the ability to quickly and easily add your own
  • CommandLineParser
    • Provides advanced command line specification with very clean, easy to read implementation
  • Serilog
    • Simply my preferring logging library
    • Configuration automatically loaded from Microsoft.Extension.Configuration
    • Taps into Microsoft.Extensions.Logging for automatic logging support for any third-party libraries that support ILogging in your project
  • Microsoft's Configuration, Dependency Injection, Logging, and Options
    • A standard set of ubiquitous libraries for familiarity and ease-of-use
    • Allows for populating configuration from appsettings.json to CommandLineParser commands
    • Allows for registering CommandLineParser commands to ServiceProvider and take advantage of dependency injection

Opinionated

Obviously there are opinions here, particularly the library choices (especially DI), but an unexpected opinion may be found when using IOptions. The library does not ask for named options or an IConfigurationSection.

Instead, it defaults to using the name of the class you are using for IOptions. Additionally, when parsing appsettings.json it looks for this name as a child to the "Commands" key.

Examples

DataFetchExample

Demonstration of configuring a console command that uses a web-based API, configured in appsettings.json, to fetch a string from the Internet and print to console.

HelloWorldExample

Your run of the mill Hello World. Program.cs registers a class inheriting ICommand (ICommandAsync also available)--quite familiar to those who use Microsoft.DependencyInjection--with the option of adding a third type to configure IOptions.

Program.cs
  • Create the builder,
  • Register your command (ICommand<TArgs>) with it's CommandLineParser argument specification (TArgs)
  • Build and run the host, passing it the incoming args.
using Cackle.ConsoleApp;
using SimpleExample;

// Create a host to handle services, configuration, and execution
var host = CommandHostBuilder.Create();

// Register our command with it's argument specification
host.RegisterCommand<HelloWorld, HelloWorldArgs>();

// Finally, build the host and run it
return host.Build().Run(args);
HelloWorld.cs

Inherit ICommand<TArgs> with your CommandLineParser argument specification (TArgs) which will require Invoke (or InvokeAsync if using ICommandAsync<TArgs>) where you perform work.

using Cackle.ConsoleApp;
using CommandLine;

namespace SimpleExample;

/// <summary>
///     Print a greeting to the console
/// </summary>
internal class HelloWorld : ICommand<HelloWorldArgs>
{
	/// <summary>
	///     Entry point into the commandAsync
	/// </summary>
	/// <param name="options">Command line arguments</param>
	/// <returns>Program exit code</returns>
	public int Invoke(HelloWorldArgs options)
	{
		if (options.Verbose) Console.WriteLine("Parsed user input, printing to screen...");
		Console.WriteLine($"Hello {options.Target}!");

		return 0;
	}
}

Finally, let CommandLineParser come in and do the heavy lifting.

/// <summary>
///     Reply with a greeting
/// </summary>
[Verb("greeting", true)]
internal class HelloWorldArgs : ICommandArgs
{
	/// <summary>
	///     Produce verbose output
	/// </summary>
	[Option('v', "verbose", Required = false, HelpText = "Set output to verbose messages.")]
	public bool Verbose { get; set; }

	/// <summary>
	///     The target of your greeting
	/// </summary>
	[Option('t', "target", Required = true, HelpText = "Who do you want to say hello to?")]
	public string Target { get; set; } = default!;
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Cackle.ConsoleApp:

Package Downloads
Cackle.ConsoleApp.Extensions.Logging.SpectreConsole

This library provides a logging provider for Microsoft.Extensions.Logging that utilizes the rich console output capabilities of Spectre.Console. It's designed to seamlessly integrate with the Cackle.ConsoleApp framework, offering styled and informative console logging within your Spectre.Console-powered applications.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.5-alpha 124 7/2/2025
2.0.3 202 5/16/2025
1.5.11 128 2/8/2025
1.5.10 155 10/25/2024
1.5.8 144 10/11/2024
1.5.7 128 10/10/2024
1.5.6 142 9/12/2024
1.5.5 145 9/4/2024
1.5.4 140 9/4/2024
1.5.3 166 8/23/2024
1.5.2 157 8/23/2024
1.5.1 154 8/23/2024
1.5.0 156 8/23/2024
1.4.0 154 8/16/2024
1.3.3 143 5/16/2024
1.3.2 135 5/10/2024
1.3.1 90 2/23/2024
1.3.0 263 11/27/2023
1.2.0-beta.1 97 10/27/2023
1.1.0 104 10/20/2023
1.0.1 70 10/19/2023
0.1.1-beta.1 99 10/7/2023
0.1.1-alpha.3 93 10/19/2023
0.1.1-alpha.2 93 10/19/2023