fwRelik.Terminal
0.1.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet tool install --global fwRelik.Terminal --version 0.1.0
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo dotnet tool install --local fwRelik.Terminal --version 0.1.0
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=fwRelik.Terminal&version=0.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
nuke :add-package fwRelik.Terminal --version 0.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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 | Versions 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.
This package has no dependencies.