Atata.Cli is a .NET library that provides an API for CLI.
The package targets .NET Standard 2.0, which supports .NET 5+, .NET Framework 4.6.1+ and .NET Core/Standard 2.0+.
- Provides an abstraction over
System.Diagnostics.Process
withCliCommand
andProgramCli
classes. - Has ability to execute CLI through command shell: cmd, sh, bash, sudo, etc.
- Provides synchronous and asynchronous API methods.
- Works on Windows, Linux and macOS.
Install Atata.Cli
NuGet package.
-
Package Manager:
Install-Package Atata.Cli
-
.NET CLI:
dotnet add package Atata.Cli
CliCommandResult result = new ProgramCli("dotnet")
.Execute("--version");
string version = result.Output;
new ProgramCli("dotnet")
.WithWorkingDirectory("some/path")
.Execute("build -c Release");
new ProgramCli("npm", useCommandShell: true)
.Execute("install -g html-validate");
The default command shell for Windows is "cmd", for other OSs it is "sh".
new ProgramCli("npm", new BashShellCliCommandFactory("-login"))
.Execute("install -g html-validate");
or
new ProgramCli("npm")
.WithCliCommandFactory(new BashShellCliCommandFactory("-login"))
.Execute("install -g html-validate");
The default shell CLI command factory can be set in a global setup/initialization method.
ProgramCli.DefaultShellCliCommandFactory = new BashShellCliCommandFactory();
ProgramCli.DefaultShellCliCommandFactory = OSDependentShellCliCommandFactory
.UseCmdForWindows()
.UseForOtherOS(new BashShellCliCommandFactory("-login"));
There are several predefined classes that implement ICliCommandFactory
:
DirectCliCommandFactory
- executes the command directly. The default one.CmdShellCliCommandFactory
- executes the command through the Windows cmd shell program.BashShellCliCommandFactory
- executes the command through the Unix Bash shell program.ShShellCliCommandFactory
- executes the command through the Unix sh shell program.SudoShellCliCommandFactory
- executes the command through the Unix sudo shell program.OSDependentShellCliCommandFactory
- executes the command through one of the registered in it shellICliCommandFactory
instances depending on the current operating system.UnixShellCliCommandFactory
- executes the command through the specified Unix shell program.ShellCliCommandFactory
- base factory class that executes the command through the specified shell program.
Any feedback, issues and feature requests are welcome.
If you faced an issue please report it to Atata.Cli Issues, ask a question on Stack Overflow using atata tag or use another Atata Contact way.
Atata Framework follows Semantic Versioning 2.0. Thus backward compatibility is followed and updates within the same major version (e.g. from 1.3 to 1.4) should not require code changes.
Atata is an open source software, licensed under the Apache License 2.0. See LICENSE for details.