|
jjm.one.CommandLineToolWrapper
2.0.0-alpha.0
A C# library that provides a wrapper for command line tools.
|
A C# library that provides a wrapper for command line tools.
| Build & Test Status (main) | |
| Nuget Package Version | |
| SonarCloudQuality Gate Status |
You can get the latest version of this software as a nuget package form nuget.org
The full documentation for this package can be found here.
The associated repo for this package can be found here.
All interfaces and classes provided by this package are briefly presented below.
This interface defines a contract for a wrapper around a command line tool. It has a single method, RunCommandAsync, which takes a command and its arguments, and returns a Task that completes with a ProcessResult.
This class is the default implementation of the IToolWrapper interface. It uses an instance of IProcessRunner to execute commands, and logs information about the tool's operations. It also has settings for the command line tool and the wrapper itself, which are provided through the constructor.
You can use the ToolWrapper class to run a command like this:
This class represents the result of a process run by the ToolWrapper. It contains the exit code of the process and optionally, the output and error messages.
When you run a command with the ToolWrapper, you get a ProcessResult:
The constructor of the ToolWrapper class takes in ToolSettings and WrapperSettings for the command line tool and the wrapper respectively. It also takes an optional IProcessRunner and ILogger<ToolWrapper>. If no IProcessRunner is provided, a new ProcessRunner is created. If no ILogger<ToolWrapper> is provided, logging is disabled.
This method is the implementation of the RunCommandAsync method from the IToolWrapper interface. It runs a command asynchronously and returns a ProcessResult.
You can use this method to run a command like this:
The AddToolWrapper method is an extension method for IServiceCollection that you can use to register the ToolWrapper class and its dependencies in the dependency injection container.
Here's an example of how you can use it in the ConfigureServices method of your Startup.cs file:
In this example, ToolSettings and WrapperSettings are being created as new instances. You might want to populate these from your application's configuration (e.g., from an appsettings.json file) instead.
Please replace YourNamespace with the actual namespace where the AddToolWrapper method is defined.
After you've registered ToolWrapper with the IServiceCollection, you can have it automatically injected into your classes by adding a parameter of type IToolWrapper to the constructor of your class:
In this example, MyClass has a dependency on IToolWrapper, which will be automatically injected by the .NET Core dependency injection framework when MyClass is created.