https://github.com/atata-framework/atata-cli
.NET library that provides an API for CLI.
https://github.com/atata-framework/atata-cli
api atata cli
Last synced: about 1 year ago
JSON representation
.NET library that provides an API for CLI.
- Host: GitHub
- URL: https://github.com/atata-framework/atata-cli
- Owner: atata-framework
- License: apache-2.0
- Created: 2021-06-23T15:21:34.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2025-04-08T14:37:52.000Z (about 1 year ago)
- Last Synced: 2025-04-19T09:04:35.192Z (about 1 year ago)
- Topics: api, atata, cli
- Language: C#
- Homepage:
- Size: 205 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Atata.Cli
[](https://www.nuget.org/packages/Atata.Cli/)
[](https://github.com/atata-framework/atata-cli/releases)
[](https://dev.azure.com/atata-framework/atata-cli/_build/latest?definitionId=41&branchName=main)
[](https://join.slack.com/t/atata-framework/shared_invite/zt-5j3lyln7-WD1ZtMDzXBhPm0yXLDBzbA)
[](https://atata.io)
[](https://twitter.com/AtataFramework)
**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+.*
## Table of Contents
- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [CLI Command Factories](#cli-command-factories)
- [Feedback](#feedback)
- [SemVer](#semver)
- [License](#license)
## Features
- Provides an abstraction over `System.Diagnostics.Process` with `CliCommand` and `ProgramCli` 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.
## Installation
Install [`Atata.Cli`](https://www.nuget.org/packages/Atata.Cli/) NuGet package.
- Package Manager:
```
Install-Package Atata.Cli
```
- .NET CLI:
```
dotnet add package Atata.Cli
```
## Usage
### Execute Command to Get Value
```cs
CliCommandResult result = new ProgramCli("dotnet")
.Execute("--version");
string version = result.Output;
```
### Execute Command in Directory
```cs
new ProgramCli("dotnet")
.WithWorkingDirectory("some/path")
.Execute("build -c Release");
```
### Execute Command Through Command Shell
```cs
new ProgramCli("npm", useCommandShell: true)
.Execute("install -g html-validate");
```
*The default command shell for Windows is "cmd", for other OSs it is "sh".*
### Execute Command Through Specific Command Shell
```cs
new ProgramCli("npm", new BashShellCliCommandFactory("-login"))
.Execute("install -g html-validate");
```
or
```cs
new ProgramCli("npm")
.WithCliCommandFactory(new BashShellCliCommandFactory("-login"))
.Execute("install -g html-validate");
```
### Set Default Shell CLI Command Factory
The default shell CLI command factory can be set in a global setup/initialization method.
#### Set for Any Operating System
```cs
ProgramCli.DefaultShellCliCommandFactory = new BashShellCliCommandFactory();
```
#### Set Specific to Operating System
```cs
ProgramCli.DefaultShellCliCommandFactory = OSDependentShellCliCommandFactory
.UseCmdForWindows()
.UseForOtherOS(new BashShellCliCommandFactory("-login"));
```
## CLI Command Factories
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
shell `ICliCommandFactory` 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.
## Feedback
Any feedback, issues and feature requests are welcome.
If you faced an issue please report it to [Atata.Cli Issues](https://github.com/atata-framework/atata-cli/issues),
[ask a question on Stack Overflow](https://stackoverflow.com/questions/ask?tags=atata+csharp) using [atata](https://stackoverflow.com/questions/tagged/atata) tag
or use another [Atata Contact](https://atata.io/contact/) way.
## SemVer
Atata Framework follows [Semantic Versioning 2.0](https://semver.org/).
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.
## License
Atata is an open source software, licensed under the Apache License 2.0.
See [LICENSE](LICENSE) for details.