ByteDev.Cmd
4.2.2
See the version list below for details.
dotnet add package ByteDev.Cmd --version 4.2.2
NuGet\Install-Package ByteDev.Cmd -Version 4.2.2
<PackageReference Include="ByteDev.Cmd" Version="4.2.2" />
paket add ByteDev.Cmd --version 4.2.2
#r "nuget: ByteDev.Cmd, 4.2.2"
// Install ByteDev.Cmd as a Cake Addin #addin nuget:?package=ByteDev.Cmd&version=4.2.2 // Install ByteDev.Cmd as a Cake Tool #tool nuget:?package=ByteDev.Cmd&version=4.2.2
ByteDev.Cmd
Library providing functionality to help when creating .NET Console applications.
Installation
ByteDev.Cmd has been written as a .NET Standard 2.0 library, so you can consume it from a .NET Core or .NET Framework 4.6.1 (or greater) application.
ByteDev.Cmd is hosted as a package on nuget.org. To install from the Package Manager Console in Visual Studio run:
Install-Package ByteDev.Cmd
Further details can be found on the nuget page.
Release Notes
Releases follow semantic versioning.
Full details of the release notes can be viewed on GitHub.
Usage
Output class
Provides wrapper functionality around the System.Console
class to make writing out output easier.
To use reference namespace: ByteDev.Cmd
.
Methods include:
- Write
- WriteLine
- WriteRainbowLine
- WriteAlignLeft
- WriteAlignRight
- WriteAlignCenter
- WriteAlignToSides
- WriteHorizontalLine
- WriteBlankLines
- WriteWrap
var output = new Output();
var color = new OutputColor(ConsoleColor.White, ConsoleColor.Blue);
output.WriteLine("Text in default colors");
output.WriteLine("Text looks a bit like default PowerShell", color);
// Message Box
var msgBox = new MessageBox("Text in a box")
{
BorderColor = new OutputColor(ConsoleColor.Red, ConsoleColor.Blue),
TextColor = new OutputColor(ConsoleColor.White, ConsoleColor.Blue)
};
output.Write(msgBox);
// Unordered List
var ul = new UnorderedList(new [] { "Item 1", "Item 2", "Item 3" })
{
ItemPrefix = "* ",
ItemColor = new OutputColor(ConsoleColor.DarkBlue, ConsoleColor.Gray)
};
output.Write(ul);
// Ordered List
var ol = new OrderedList(new[] { "Item 1", "Item 2", "Item 3" })
{
ItemStartingNumber = 0,
ItemColor = new OutputColor(ConsoleColor.Black, ConsoleColor.Yellow),
ApplyItemNumberPadding = true
};
output.Write(ol);
// Tables
var table = new Table(3, 3)
{
BorderStyle = new BorderSimple(),
BorderColor = new OutputColor(ConsoleColor.White, ConsoleColor.Blue),
ValueColor = new OutputColor(ConsoleColor.White, ConsoleColor.Blue)
};
table.UpdateCell(new CellPosition(0, 0), new Cell("A1")
{
ValueColor = new OutputColor(ConsoleColor.DarkBlue, ConsoleColor.White)
});
table.UpdateCell(new CellPosition(0, 1), new Cell("B1"));
table.UpdateCell(new CellPosition(1, 1), new Cell("B2"));
table.UpdateCell(new CellPosition(2, 1), new Cell("B3"));
table.UpdateCell(new CellPosition(2, 2), new Cell("C3"));
output.Write(table);
Logger class
The Logger
class provides a convenient way to write log style messages to the console based on a given LogLevel
.
To use reference namespace: ByteDev.Cmd.Logging
.
Methods include:
- WriteDebug
- WriteInfo
- WriteWarning
- WriteError
- WriteCritical
// Example: at LogLevel.Error only Error and Critical messages will be written
var logger = new Logger(LogLevel.Error);
logger.WriteDebug("Debug message");
logger.WriteInfo("Info message");
logger.WriteWarning("Warning message");
logger.WriteError("Error message");
logger.WriteCritical("Critical message");
Arguments namespace
To use reference namespace: ByteDev.Cmd.Arguments
.
The namespace defines a number of types:
CmdAllowedArg
- represents an allowed argument.CmdArgInfo
- representsstring[] args
from the console app and a collection ofCmdAllowedArg
.CmdArg
- represents an input command line argument.
// Define what arguments are allowed using the CmdAllowedArg class
var cmdAllowedArgs = new List<CmdAllowedArg>
{
new CmdAllowedArg('o', false)
{
LongName = "output",
Description = "Output something"
},
new CmdAllowedArg('p', true)
{
LongName = "path",
Description = "Set a path",
IsRequired = true
}
};
try
{
// Handle console arguments using the CmdArgInfo class
// args is the string array of args from Program.Main
var cmdArgInfo = new CmdArgInfo(args, cmdAllowedArgs);
// Use CmdArgInfo instance to determine what operations to perform
if (cmdArgInfo.HasArguments)
{
foreach (CmdArg cmdArg in cmdArgInfo.Arguments)
{
switch (cmdArg.ShortName)
{
case 'o':
DoSomeOutput();
break;
case 'p':
SetPath(cmdArg.Value);
break;
}
}
}
else
{
Console.WriteLine(cmdAllowedArgs.HelpText());
}
}
catch (CmdArgException ex)
{
// When creating CmdArgInfo if any invalid input a CmdArgException will be thrown
Console.WriteLine(ex.Message);
Console.WriteLine(cmdAllowedArgs.HelpText());
}
The ByteDev.Cmd.TestApp
project on GitHub also has a working example of this.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
5.0.0 | 468 | 4/5/2021 |
4.2.2 | 331 | 3/31/2021 |
4.2.1 | 379 | 12/14/2020 |
4.1.1 | 666 | 4/12/2020 |
4.1.0 | 547 | 12/5/2019 |
4.0.0 | 536 | 11/8/2019 |
3.1.0 | 541 | 11/6/2019 |
3.0.1 | 524 | 11/5/2019 |
3.0.0 | 518 | 11/5/2019 |
2.1.0 | 510 | 11/4/2019 |
2.0.0 | 532 | 10/21/2019 |
1.2.0 | 517 | 10/19/2019 |
1.1.1 | 551 | 10/7/2019 |
1.1.0 | 535 | 10/6/2019 |
1.0.1 | 561 | 8/7/2019 |
1.0.0 | 907 | 6/12/2018 |