fwRelik.Terminal 0.2.4

dotnet add package fwRelik.Terminal --version 0.2.4
NuGet\Install-Package fwRelik.Terminal -Version 0.2.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="fwRelik.Terminal" Version="0.2.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add fwRelik.Terminal --version 0.2.4
#r "nuget: fwRelik.Terminal, 0.2.4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install fwRelik.Terminal as a Cake Addin
#addin nuget:?package=fwRelik.Terminal&version=0.2.4

// Install fwRelik.Terminal as a Cake Tool
#tool nuget:?package=fwRelik.Terminal&version=0.2.4

fwRelik.Terminal

Makes it easier to enter commands and process data from output.

Under the hood, the process uses a PowerShell.

TerminalClient Class

  • Namespace: fwRelik.Terminal
  • Assembly: fwRelik.Terminal.dll

📋 Methods

Methods Description
Command Allows you to execute a command and process.

📄 Examples

Command

const string command = "dir | Select-Object -Property Name";
TerminalClient.Command(command, process =>
{
    if (process.Error is not null) throw process.Error;

    // Lists all filenames in the given directory.
    Console.WriteLine(process.StdOut);
});

TerminalParser Class

  • Namespace: fwRelik.Terminal.Extensions
  • Assembly: fwRelik.Terminal.dll

📋 Methods

Methods Description
CheckValue Checking value in output.
ParseToNumarationRow Parsing the output to create a line-by-line data format.

📄 Examples

CheckValue

const string command = "Get-ExecutionPolicy -List";
TerminalClient.Command(command, process =>
{
    if (process.Error is not null) throw process.Error;

    bool result = TerminalParser.CheckValue(
        stdOut: process.StdOut,
        keyword: "LocalMachine",
        stateValue: "Unrestricted"
    );

    Console.WriteLine($"Local Machine Execution policy is Unrestricted: {result}");
});

If the result and the keyword are the same, then the output can be checked like this:

const string command = "Test-Path 'C:\Windows\System32'";
TerminalClient.Command(command, process =>
{
    if (process.Error is not null) throw process.Error;

    bool result = TerminalParser.CheckValue(
        stdOut: process.StdOut,
        keyword: "True",
        stateValue: "True"
    );

    Console.WriteLine($"Local Machine Execution policy is Unrestricted: {result}");
});

In this way, it is possible to check the boolean value and much more for the complete conformity of the output.

Searching on a different line from the keyword can be done with an additional parameter of stateRow by default it is 0.

ParseToNumarationRow

const string command = "dir | Select-Object -Property Mode, Name";
TerminalClient.Command(command, process =>
{
    if (process.Error is not null) throw process.Error;
    
    string[] rows = TerminalParser.ParseToNumarationRow(process.StdOut);

    for (int i = 0; i < rows.Length; i++)
        Console.WriteLine($"[{i}] : {rows[i]}");
});

There is also the meaning of padding. Indentation from above. Values within this range will be excluded from the list. Default value: 0.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on fwRelik.Terminal:

Package Downloads
fwRelik.SSHSetup

Setting OpenSSH

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.2.4 257 3/2/2023
0.2.3 472 3/1/2023
0.2.2 219 3/1/2023
0.2.1 225 3/1/2023
0.2.0 212 3/1/2023
0.1.0 219 2/28/2023