CliRunner 1.0.0-beta.3
dotnet add package CliRunner --version 1.0.0-beta.3
NuGet\Install-Package CliRunner -Version 1.0.0-beta.3
<PackageReference Include="CliRunner" Version="1.0.0-beta.3" />
paket add CliRunner --version 1.0.0-beta.3
#r "nuget: CliRunner, 1.0.0-beta.3"
// Install CliRunner as a Cake Addin #addin nuget:?package=CliRunner&version=1.0.0-beta.3&prerelease // Install CliRunner as a Cake Tool #tool nuget:?package=CliRunner&version=1.0.0-beta.3&prerelease
CliRunner
CliRunner is a library for interacting with Command Line Interfaces and wrapping around executables.
<img src="https://github.com/alastairlundy/CliRunner/blob/main/.assets/icon.png" width="192" height="192" alt="CliRunner Logo">
Table of Contents
- Features
- Why CliRunner?
- Installing CliRunner
- CLiRunner Examples * Executing Commands
- Contributing to CliRunner
- Roadmap
- License
- Acknowledgements
Features
- Promotes the single responsibility principle and separation of concerns
- For .NET 8 and newer TFMs CliRunner has few dependencies.
- Compatible with .NET Standard 2.0 and 2.1 ^1
- Dependency Injection extensions to make using it easier.
- Support for specific specializations such as running executables or commands via Windows Powershell or CMD on Windows ^2
- SourceLink support
^1 - Polyfill is a dependency only required for .NET Standard 2.0 and 2.1 users. Microsoft.Bcl.HashCode is a dependency only required for .NET Standard 2.0 users.
^2 - The Specialization library is distributed separately.
Why use CliRunner over CliWrap?
- Greater separation of concerns with the Command class - Command Building, Command Running, andCommand Pipe handling are moved to separate classes.
- Supports Dependency Injection
- Classes and code follow the Single Responsibility Principle
- No hidden or additional licensing terms are required beyond the source code license.
- No imported C code - This library is entirely written in C#.
- No lock in regarding Piping support
- Uses .NET's built in
Process
type.
How to install and use CliRunner
CliRunner is available on Nuget.
These are the CliRunner projects:
- CliRunner - The main CliRunner package.
- CliRunner.Extensions.DependencyInjection
- CliRunner.Specializations
Installing CliRunner
CliRunner's packages can be installed via the .NET SDK CLI, Nuget via your IDE or code editor's package interface, or via the Nuget website.
Package Name | Nuget Link | .NET SDK CLI command |
---|---|---|
CliRunner | CliRunner Nuget | dotnet add package CliRunner |
CliRunner.Extensions.DependencyInjection | CliRunner.Extensions.DependencyInjection Nuget | dotnet add package CliRunner.Extensions.DependencyInjection |
CliRunner.Specializations | CliRunner.Specializations Nuget | dotnet add package CliRunner.Specializations |
Supported Platforms
CliRunner can be added to any .NET Standard 2.0, .NET Standard 2.1, .NET 8, or .NET 9 supported project.
The following table details which target platforms are supported for executing commands via CliRunner.
Operating System | Support Status | Notes |
---|---|---|
Windows | Fully Supported ✅ | |
macOS | Fully Supported ✅ | |
Mac Catalyst | Untested Platform ⚠️ | Support for this platform has not been tested but should theoretically work. |
Linux | Fully Supported ✅ | |
FreeBSD | Fully Supported ✅ | |
Android | Untested Platform ⚠️ | Support for this platform has not been tested but should theoretically work. |
IOS | Not Supported ❌ | Not supported due to Process.Start() not supporting IOS. ^3 |
tvOS | Not Supported ❌ | Not supported due to Process.Start() not supporting tvOS ^3 |
watchOS | Not Supported ❌ | Not supported due to Process.Start() not supporting watchOS ^4 |
Browser | Not Supported and Not Planned ❌ | Not supported due to not being a valid target Platform for executing programs or processes. |
^3 - See the Process class documentation for more info.
^4 - Lack of watchOS support is implied by lack of IOS support since watchOS is based on IOS.
Note: This library has not been tested on Android or Tizen!
Using CliRunner / Examples
One of the main use cases for CliRunner is intended to be executing programs programatically, but other valid use cases also exist such as safer Process Running.
Executing Commands
CliRunner enables use of a fluent builder style of syntax to easily configure and run Commands.
The following example shows how to configure and build a Command that returns a BufferedProcessResult which contains redirected StandardOutput and StandardError as strings.
using CliRunner;
using CliRunner.Builders.Abstractions;
using CliRunner.Builders;
using AlastairLundy.Extensions.Processes;
//Namespace and classs code ommitted for clarity
// ServiceProvider and Dependency Injection code ommitted for clarity
ICommandRunner _commandRunner = serviceProvider.GetRequiredService<ICommandRunner>();
// Fluently configure your Command.
ICommandBuilder builder = new CommandBuilder("Path/To/Executable")
.WithArguments(["arg1", "arg2"])
.WithWorkingDirectory("/Path/To/Directory");
// Build it as a Command object when you're ready to use it.
Command command = builder.Build();
// Execute the command through CommandRunner and get the results.
BufferedProcessResult result = await _commandRunner.ExecuteBufferedAsync(command);
How to Build CliRunner's code
Requirements
CliRunner requires the latest .NET release SDK to be installed to target all supported TFM (Target Framework Moniker) build targets.
Currently, the required .NET SDK is .NET 9.
The current build targets include:
- .NET 8
- .NET 9
- .NET Standard 2.0
- .NET Standard 2.1
Any version of the .NET 9 SDK can be used, but using the latest version is preferred.
Versioning new releases
CliRunner aims to follow Semantic versioning with [Major].[Minor].[Build]
for most circumstances and an optional .[Revision]
when only a configuration change is made, or a new build of a preview release is made.
Pre-releases
Pre-release versions should have a suffix of -alpha, -beta, -rc, or -preview followed by a .
and what pre-release version number they are. The number should be incremented by 1 after each release unless it only contains a configuration change, or another packaging, or build change. An example pre-release version may look like 1.1.0-alpha.2 , this version string would indicate it is the 2nd alpha pre-release version of 1.1.0 .
Stable Releases
Stable versions should follow semantic versioning and should only increment the Revision number if a release only contains configuration or build packaging changes, with no change in functionality, features, or even bug or security fixes.
Releases that only implement bug fixes should see the Build version incremented.
Releases that add new non-breaking changes should increment the Minor version. Minor breaking changes may be permitted in Minor version releases where doing so is necessary to maintain compatibility with an existing supported platform, or an existing piece of code that requires a breaking change to continue to function as intended.
Releases that add major breaking changes or significantly affect the API should increment the Major version. Major version releases should not be released with excessive frequency and should be released when there is a genuine need for the API to change significantly for the improvement of the project.
Building for Testing
You can build for testing by building the desired project within your IDE or VS Code, or manually by entering the following command: dotnet build -c Debug
.
If you encounter any bugs or issues, try running the CliRunner.Tests
project and setting breakpoints in the affected CliRunner project's code where appropriate. Failing that, please report the issue if one doesn't already exist for the bug(s).
Building for Release
Before building a release build, ensure you apply the relevant changes to the relevant .csproj
file corresponding to the package you are trying to build:
- Update the Package Version variable
- Update the project file's Changelog
- Remove/replace the CliRunner icon if distributing a non-official release build to a wider audience. See CliRunner Assets for more details.
You should ensure the project builds under debug settings before producing a release build.
Producing Release Builds
To manually build a project for release, enter dotnet build -c Release /p:ContinuousIntegrationBuild=true
for a release with SourceLink enabled or just dotnet build -c Release
for a build without SourceLink.
Builds should generally always include Source Link and symbol packages if intended for wider distribution.
NOTES:
CliRunner.Specializations
andCliRunner.Extensions.DependencyInjection
both take a dependency on the CliRunner base package from Nuget - For the respective libraries to use a newer CliRunner version, that version must be published on Nuget.
How to Contribute to CliRunner
Thank you in advance for considering contributing to CliRunner.
Please see the CONTRIBUTING.md file for code and localization contributions.
If you want to file a bug report or suggest a potential feature to add, please check out the GitHub issues page to see if a similar or identical issue is already open. If there is not already a relevant issue filed, please file one here and follow the respective guidance from the appropriate issue template.
Thanks.
CliRunner's Roadmap
CliRunner aims to make working with Commands and external processes easier.
Whilst an initial set of features are available in version 1, there is room for more features, and for modifications of existing features in future updates.
That being said, all stable releases from 1.0 onwards must be stable and should not contain regressions.
Future updates should aim focus on one or more of the following:
- Improved ease of use
- Improved stability
- New features
- Enhancing existing features
License
CliRunner is licensed under the MPL 2.0 license. If you modify any of CliRunner's files then the modified files must be licensed under the MPL 2.0 .
If you use CliRunner in your project please make an exact copy of the contents of CliRunner's LICENSE.txt file available either in your third party licenses txt file or as a separate txt file.
CliRunner Assets
CliRunner's Icon is NOT licensed under the MPL 2.0 license and are licensed under Copyright with all rights reserved to me (Alastair Lundy).
If you fork CliRunner and re-distribute it, please replace the usage of the icon unless you have prior written agreements from me.
Acknowledgements
Projects
This project would like to thank the following projects for their work:
For more information, please see the THIRD_PARTY_NOTICES file.
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 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 is compatible. 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. |
.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 is compatible. |
.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
- AlastairLundy.Extensions.Processes (>= 1.1.0 && < 2.0.0)
- AlastairLundy.Extensions.System (>= 6.0.0 && < 7.0.0)
- PolyFill (>= 7.17.0 && < 8.0.0)
-
.NETStandard 2.1
- AlastairLundy.Extensions.Processes (>= 1.1.0 && < 2.0.0)
- AlastairLundy.Extensions.System (>= 6.0.0 && < 7.0.0)
- PolyFill (>= 7.17.0 && < 8.0.0)
-
net8.0
- AlastairLundy.Extensions.Processes (>= 1.1.0 && < 2.0.0)
- AlastairLundy.Extensions.System (>= 6.0.0 && < 7.0.0)
-
net9.0
- AlastairLundy.Extensions.Processes (>= 1.1.0 && < 2.0.0)
- AlastairLundy.Extensions.System (>= 6.0.0 && < 7.0.0)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on CliRunner:
Package | Downloads |
---|---|
PlatformKit
Cross-platform Operating System Detection, Operating System Version Detection, Apple Silicon Mac Detection, programmatic .NET Runtime ID Generation, and more. For a full list of features please visit: https://github.com/alastairlundy/PlatformKit/blob/main/docs/FeatureComparisonByPlatform.md |
|
CliRunner.Specializations
CliRunner Specializations is a library for providing Specializations of CliRunner's Commands. |
|
CliRunner.Extensibility
Makes extending CliRunner, and using custom Command Runners and Command Configurations easier. |
|
CliRunner.Extensions
Adds a ``AddCliRunner`` Dependency Injection extension method to enable easy CliRunner setup when using the Microsoft.Extensions.DependencyInjection package. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0-beta.3 | 61 | 2/20/2025 |
1.0.0-beta.2 | 79 | 2/18/2025 |
1.0.0-beta.1 | 84 | 2/14/2025 |
## Changes
- Renamed ``Command`` to ``CliCommand``
- Renamed ``CommandBuilder`` to ``CliCommandBuilder``
- Renamed ``ICommandBuider`` to ``ICliCommandBuilder``
- Renamed ``ICommandConfiguration`` to ``ICliCommandConfiguration``