Skip to content

Latest commit

 

History

History
137 lines (97 loc) · 4.63 KB

README.md

File metadata and controls

137 lines (97 loc) · 4.63 KB

Atata.Cli

NuGet GitHub release Build status Slack Atata docs Twitter

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

  • 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 NuGet package.

  • Package Manager:

    Install-Package Atata.Cli
    
  • .NET CLI:

    dotnet add package Atata.Cli
    

Usage

Execute Command to Get Value

CliCommandResult result = new ProgramCli("dotnet")
    .Execute("--version");

string version = result.Output;

Execute Command in Directory

new ProgramCli("dotnet")
    .WithWorkingDirectory("some/path")
    .Execute("build -c Release");

Execute Command Through Command Shell

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

new ProgramCli("npm", new BashShellCliCommandFactory("-login"))
    .Execute("install -g html-validate");

or

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

ProgramCli.DefaultShellCliCommandFactory = new BashShellCliCommandFactory();

Set Specific to Operating System

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, ask a question on Stack Overflow using atata tag or use another Atata Contact way.

SemVer

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.

License

Atata is an open source software, licensed under the Apache License 2.0. See LICENSE for details.