CSF.NET.Spectre 1.2.2.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package CSF.NET.Spectre --version 1.2.2.1                
NuGet\Install-Package CSF.NET.Spectre -Version 1.2.2.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="CSF.NET.Spectre" Version="1.2.2.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CSF.NET.Spectre --version 1.2.2.1                
#r "nuget: CSF.NET.Spectre, 1.2.2.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.
// Install CSF.NET.Spectre as a Cake Addin
#addin nuget:?package=CSF.NET.Spectre&version=1.2.2.1

// Install CSF.NET.Spectre as a Cake Tool
#tool nuget:?package=CSF.NET.Spectre&version=1.2.2.1                

csfbanner_lighttrans_outline

πŸ—οΈ CSF.NET - Command Standardization Framework for .NET

CSF is an attribute based framework that makes creating and processing text based commands easy for any platform. It implements a modular, easy to implement pipeline for registering and executing commands, as well as a large number of extensions to make development on different platforms as easy as possible.

πŸ“ Features

πŸ—¨οΈ Automated parameter parsing:

ValueType and nullable variant types are automatically parsed by the library and populate commands as below:

[Command("handle")]
public IResult Handle(int param1, DateTime param2)
{
    return Respond("{0}, {1}", param1, param2);
}

This will automatically parse int by using the default int.TryParse implementation, and will do the same for the DateTime.

Outside of this, implementing and adding your own TypeReader's is also supported to handle implementing commands with your own types. Nullability is automatically resolved by the library.

🧾 Parameterized remainder:

RemainderAttribute defines that all remaining parameters should be concatenated into a single 'remaining' string. This ensures that you don't need to add quotation marks for longer strings such as providing reasons, passwords or directories:

[Command("handle")]
public void Handle([Remainder] string path)
{
    if (!Path.Exists(path))
        Error("Failed to find specified path!");
}

πŸ›‘ Command preconditions.

Inheriting PreconditionAttribute creates a new precondition to add in the attribute range above commands. When a command is tried to be executed, it will walk through every added precondition and abort execution if any of them fail.

[RequireSystem(PlatformID.Unix)]
[Command("copy")]
public async Task Handle()
{
    
}

πŸ“– Exposed command info & responsive errors:

CSF.NET will return results for building the command map and executing commands. If you want to run your commands asynchronously, you will have to handle the result process differently:

_csf.CommandExecuted += async (context, result) => 
{
    await Task.CompletedTask;
    if (result.IsSuccess)
        return;
    // handle failure.
}

πŸ”— Virtual base class to support freely overriding all results:

Every single method inside the CommandFramework is virtual and can be overwritten if desired to change results or rewrite certain steps inside the pipeline.

πŸ’‘ Support for overriding context, module & framework:

IContext can be implemented in your own way, as it by itself serves as just a parsing tool. You can add a number of application-unique properties that are populated at creation. Because of how context's are created, it is easy to implement your own constructors and populate values from your own codebase.

πŸ’‰ Dependency injection:

You can provide an IServiceProvider at execution to inject modules with dependencies. Modules are transient and will re-inject the expected services into the module every time a command is executed. Nullable services will not populate if the constructor parameter is declared as nullable.

πŸ—ΊοΈ Roadmap

  • Add support for flags.
  • Add regex parameter support.
  • Add complex parameters.
  • Wrap around other potential frameworks.
  • Implement extensions for IHost and WebHost.

πŸ€– Samples

Samples are available to learn how to implement CSF in your own programs.

πŸ“° Extensions

CSF introduces a number of extensions for external libraries.

❓ Explaining the internals:

CSF.NET works by grabbing all available modules on the specified assembly, storing them into a command map, and running through the pipeline to enter and execute the target command method.

🏭 Build steps:

Building the command map is done in a number of steps to ensure the pipeline can run through it succesfully.

  • Find all types in the provided assembly and check if they inherit ModuleBase<>.
  • Find all methods signed with CommandAttribute, if any.
  • Create a new Module from the found module, and create a new Command for each command within.
  • Populate the information with all found TypeReaders, PreconditionAttributes, attributes and aliases.
  • Add all aliases for the command to the commandmap, sharing a reference to the same target command.

The entire build process resides here.

πŸ”— Pipeline steps:

The pipeline runs through several steps, in order, to make sure your command can safely pass through to its executing method.

  • Look up all available commands matching the provided name.
  • Find the best command match for the amount of provided parameters.
  • Check all PreconditionAttributes to see if any fail.
  • Construct the module and inject found services from the provided IServiceProvider
  • Iterate through the parameters with provided TypeReaders and create a range of parsed parameters from the result.
  • Run the BeforeExecuteAsync method.
  • Run the command method.
  • Run the AfterExecuteAsync method.
  • Return a result to the caller.

The entire pipeline process resides here.

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

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.0 132 1/19/2024
2.0.0 134 10/8/2023
1.4.1 306 12/17/2022
1.4.0 323 11/23/2022
1.3.0 305 11/21/2022
1.2.2.1 343 11/13/2022
1.2.2 322 11/10/2022
1.2.1 309 11/9/2022
1.2.0 472 10/31/2022
1.1.0 370 10/23/2022
1.0.1 376 10/6/2022
0.1.1-beta 158 9/29/2022
0.1.0-beta 177 9/28/2022

Version 1.2.2.1; Made for netstandard2.0.