ConsoleFx is a suite of .NET libraries for building command-line (CLI) applications.
The following code simulates the following made-up console app:
COPY <source file> [<destination dir>] [--overwrite] [--create-dir]
public class Program : ConsoleProgram
{
// Declare one property per argument and option.
public string SourceFile { get; set; }
public string DestinationDir { get; set; }
[Option("overwrite")]
public bool OverwriteExistingFile { get; set; }
[Option("create-dir")]
public bool CreateDirIfMissing { get; set; }
// Code to execute the console program if all command line args are verified.
protected int HandleCommand()
{
Console.WriteLine($"You want to copy {SourceFile} to {DestinationDir}");
Console.WriteLine($"Overwrite file if it exists: {OverwriteExistingFile}");
Console.WriteLine($"Create destination directory if it does not exist: {CreateDirIfMissing}");
return 0;
}
// Specify the options and arguments that are accepted by the console app
protected override IEnumerable<Arg> GetArgs()
{
yield return new Argument(nameof(SourceFile))
.ValidateAsFile(shouldExist: true);
yield return new Argument(nameof(DestinationDir), optional: true)
.ValidateAsDirectory();
yield return new Option("overwrite", "o")
.UsedAsFlag();
yield return new Option("create-dir", "c")
.UsedAsFlag();
}
public static int Main()
{
var program = new Program();
return program.Run();
}
}
ConsoleFx consists of the following NuGet packages. Development packages from continuous integration builds are available on MyGet.
Package | Description | Dev Build |
---|---|---|
ConsoleFx.CmdLine.Program |
Write command line programs with sophisticated argument parsing, including error handling, automatic help generation and rich validation support. Supports both Unix and Windows-style arguments. | |
ConsoleFx.CmdLine.Parser |
Standalone argument parser that is used by ConsoleFx.CmdLine.Program . Can be used in non-console program such as Windows Forms, WPF, REPL, etc. to parse command line arguments in a similar fashion. |
|
ConsoleFx.ConsoleExtensions |
Extended console capabilities like color output, prompts, inputting secrets, outputting indented text, progress bars, etc. | |
ConsoleFx.Prompter |
Rich interactive framework from getting inputs from users. Inspired by the Inquirer.js framework for JavaScript. |
ConsoleFx includes a metapackage that contains all the major packages that would typically needed to build a complex console application.
The following packages are under development and expected in a future release.
Package | Description | Expected Version |
---|---|---|
ConsoleFx.Art |
Output ASCII art in different styles. | 2.1 |
ConsoleFx.UI |
Dynamic creation of Windows Forms and WPF UI to visually input command-line arguments. | TBD |