Commandy.Abstractions
1.0.4
dotnet add package Commandy.Abstractions --version 1.0.4
NuGet\Install-Package Commandy.Abstractions -Version 1.0.4
<PackageReference Include="Commandy.Abstractions" Version="1.0.4" />
<PackageVersion Include="Commandy.Abstractions" Version="1.0.4" />
<PackageReference Include="Commandy.Abstractions" />
paket add Commandy.Abstractions --version 1.0.4
#r "nuget: Commandy.Abstractions, 1.0.4"
#:package Commandy.Abstractions@1.0.4
#addin nuget:?package=Commandy.Abstractions&version=1.0.4
#tool nuget:?package=Commandy.Abstractions&version=1.0.4
Commandy
Commandy is a powerful, cross-platform .NET library for executing shell commands and processes. It provides a simple, intuitive API for running commands on both Windows and Linux environments, with support for synchronous and asynchronous execution.
Features
- Cross-Platform Support: Works seamlessly on Windows and Linux.
- Flexible Execution: Support for both synchronous and asynchronous command execution.
- Shell and Non-Shell Execution: Run commands with or without using the system shell.
- Configurable Options: Customize working directory, environment variables, and command arguments.
- Event-Driven Output: Real-time access to command output and error streams via events.
- Cancellation Support: Cancel long-running commands using cancellation tokens.
- Extensible Design: Easy to extend for custom requirements.
- Piping Support: Chain commands together by piping output from one command to another.
- Chaining Support: Combine multiple commands into a seamless workflow.
- Timeout Handling: Set timeouts for command execution to prevent hanging processes.
- Environment Variable Management: Easily set and manage environment variables for commands.
- Working Directory Configuration: Specify the working directory for command execution.
- Argument Builder: Fluent interface for building complex command arguments.
- Dependency Injection Support: Seamlessly integrate with .NET dependency injection containers.
Installation
Install Commandy via NuGet:
dotnet add package Commandy
For DI capability:
dotnet add package Commandy.DependencyInjection
Quick Start
Here's a simple example to get you started:
using Commandy;
// Create and execute a command
var result = CommandProvider.CreateCommand("echo", opt=>opt.AddArgument("Hello, World!")
.Execute();
Console.WriteLine($"Output: {result.Output}");
Console.WriteLine($"Exit Code: {result.ExitCode}");
Advanced Usage
Asynchronous Execution
var command = CommandProvider.CreateCommand("long-running-process");
var result = await command.ExecuteAsync();
Custom Options
var command = CommandProvider.CreateCommand("git", opt => opt
.UseShell(false)
.AddEnvironmentVariable("GIT_CREDS_PATH", "/path/to/cred/file")
.AddArgument("clone")
.AddArgument("https://github.com/example/repo.git")
.WorkingDirectory("/path/to/directory")
.Timeout(TimeSpan.FromMinutes(5))
);
Event Handling
var command = Command.CreateCommand("dir");
command.OnDataReceived += (sender, args) => Console.WriteLine($"Received: {args.Data}");
command.OnErrorReceived += (sender, args) => Console.WriteLine($"Error: {args.Error}");
await command.ExecuteAsync();
Command Chaining
var chainedCommand = CommandProvider.CreateCommand("echo", opt=>opt.AddArgument("Has Error!");
var command = CommandProvider.CreateCommand("errory-command", opt => opt.ChainTo(chaindedCommand,CommandChainType.Or)
);
var result = command.Execute();
Command Piping
var grepCommand = CommandProvider.CreateCommand("grep", opt=>opt.AddArgument("error");
var command = CommandProvider.CreateCommand("cat", opt => opt.AddArgument("log.txt").PipeTo(grepCommand));
var result = command.Execute();
Using with Dependency Injection
services.AddCommandy();
// In your code:
public class MyService
{
private readonly ICommandProvider _commandProvider;
public MyService(ICommandProvider commandProvider)
{
_commandProvider = commandProvider;
}
public void RunCommand()
{
var command = _commandProvider.CreateCommand("echo", opt=>opt.AddArgument("Hello from DI!");
var result = command.Execute();
Console.WriteLine(result.Output);
}
}
Documentation
For full documentation, please visit our Wiki.
License
Commandy is licensed under the MIT License.
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. 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. |
.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
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Commandy.Abstractions:
Package | Downloads |
---|---|
Commandy
A powerful, cross-platform .NET library for executing shell commands and processes. It provides a simple, intuitive API for running commands on both Windows and Linux environments, with support for synchronous and asynchronous execution. |
|
Commandy.DependencyInjection
A powerful, cross-platform .NET library for executing shell commands and processes. It provides a simple, intuitive API for running commands on both Windows and Linux environments, with support for synchronous and asynchronous execution. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial package publish