CSF.NET.Spectre
1.4.1
See the version list below for details.
dotnet add package CSF.NET.Spectre --version 1.4.1
NuGet\Install-Package CSF.NET.Spectre -Version 1.4.1
<PackageReference Include="CSF.NET.Spectre" Version="1.4.1" />
paket add CSF.NET.Spectre --version 1.4.1
#r "nuget: CSF.NET.Spectre, 1.4.1"
// Install CSF.NET.Spectre as a Cake Addin #addin nuget:?package=CSF.NET.Spectre&version=1.4.1 // Install CSF.NET.Spectre as a Cake Tool #tool nuget:?package=CSF.NET.Spectre&version=1.4.1
ποΈ 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 defaultint.TryParse
implementation, and will do the same for theDateTime
.
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 complex parameters.
π€ Samples
Samples are available to learn how to implement CSF in your own programs.
- CSF.Samples.Hosting
- Shows how to implement CSF in an IHost design console application.
- CSF.Samples.Console
- Shows how to implement CSF on a basic console application.
- CSF.Samples.TShock4
- Shows how to implement CSF.NET.TShock into an OTAPI2 TShock plugin.
- CSF.Samples.TShock5
- Shows how to implement CSF.NET.TShock into an OTAPI3 TShock plugin.
π° Extensions
CSF introduces a number of extensions for external libraries.
- CSF.Hosting
- A package that wraps around Microsoft.Extensions.Hosting.
- CSF.Spectre
- A package that wraps around Spectre.Console.
- CSF.TShock
- A package that wraps around TShock for Terraria.
β 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 newCommand
for each command within. - Populate the information with all found
TypeReader
s,PreconditionAttribute
s, 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
PreconditionAttribute
s to see if any fail. - Construct the module and inject found services from the provided
IServiceProvider
- Iterate through the parameters with provided
TypeReader
s 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 | Versions 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. |
-
.NETStandard 2.0
- CSF.NET (>= 1.4.1)
- Spectre.Console (>= 0.45.0)
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 | 479 | 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.4.1; Made for netstandard2.0.