A powerful extension library for CommandLineParser that automatically generates interactive text-based UIs from your command-line verb definitions. Transform your CLI applications into user-friendly, menu-driven experiences without writing any additional UI code.
This repository contains two separate solutions:
- InteractiveUI.sln - The core reusable library that extends CommandLineParser
- InteractiveUI.Samples.sln - Sample applications demonstrating the library
β¨ Automatic UI Generation - Dynamically generates interactive menus from CommandLineParser verb and option attributes
π¨ Rich Console UI - Beautiful colored menus with headers, prompts, and validation
π§ Flexible Integration - Works alongside normal command-line parsing, extending rather than replacing it
π Type-Aware Input - Smart prompts based on option types (boolean, string, numeric, etc.)
β
Validation - Built-in validation for required fields and type checking
ποΈ Fluent API - Clean builder pattern for easy configuration
β‘ Dual-Mode Support - Applications work as both traditional CLI and interactive menu systems
-
Reference the library in your
.csproj:<ItemGroup> <ProjectReference Include="..\CommandLineParser.InteractiveUI\CommandLineParser.InteractiveUI.csproj" /> </ItemGroup>
-
Define your command options with standard CommandLineParser attributes:
using CommandLine; [Verb("list", HelpText = "List files in a directory.")] public class ListOptions { [Option('d', "directory", Required = false, Default = ".", HelpText = "Directory to list files from.")] public string Directory { get; set; } = "."; [Option('r', "recursive", Required = false, Default = false, HelpText = "Search recursively in subdirectories.")] public bool Recursive { get; set; } }
-
Create a command executor:
using CommandLineParser.InteractiveUI.Infrastructure; public class MyCommandExecutor : ICommandLineParser { public int Execute(string[] args) { return Parser.Default.ParseArguments<ListOptions>(args) .MapResult( (ListOptions opts) => ExecuteList(opts), errs => 1); } private int ExecuteList(ListOptions opts) { Console.WriteLine($"Listing: {opts.Directory}"); // Your implementation... return 0; } }
-
Launch the interactive UI:
using CommandLineParser.InteractiveUI; class Program { static int Main(string[] args) { var executor = new MyCommandExecutor(); // Traditional CLI mode if args provided if (args.Length > 0) return executor.Execute(args); // Interactive mode when launched without arguments var ui = InteractiveUI .CreateFrom<ListOptions, ListOptions, ListOptions>() .WithParser(executor) .Build(); ui.Run(); return 0; } }
CommandLineParser.InteractiveUI/
βββ InteractiveUI.sln # Core library solution
βββ InteractiveUI.Samples.sln # Sample applications solution
βββ README.md # This file
βββ STRUCTURE.md # Detailed structure documentation
βββ License.md # License information
β
βββ src/
βββ CommandLineParser.InteractiveUI/ # Core library
β βββ InteractiveUI.cs # Main UI implementation
β βββ InteractiveUIBuilder.cs # Fluent builder
β βββ ParserExtensions.cs # Extension methods
β βββ README.md # Library-specific docs
β βββ Infrastructure/ # Interfaces and adapters
β βββ Metadata/ # Reflection metadata extraction
β
βββ InteractiveUI.Sample.Options/ # Sample: Command options
βββ InteractiveUI.Sample.Commands/ # Sample: Command implementations
βββ InteractiveUI.Sample.Demo/ # Sample: Demo application
The core library that provides the interactive UI functionality. Open this solution to:
- Modify or extend the library
- Build the library for distribution
- View the library source code
Contains:
CommandLineParser.InteractiveUI- The main library project
Sample applications demonstrating library usage. Open this solution to:
- See working examples of the library in action
- Learn implementation patterns
- Test the library with sample commands
Contains:
InteractiveUI.Sample.Options- Sample command option definitionsInteractiveUI.Sample.Commands- Sample command implementationsInteractiveUI.Sample.Demo- Console application demonstrating dual-mode (CLI + Interactive)
# Build the library
dotnet build InteractiveUI.sln# Build the sample solution
dotnet build InteractiveUI.Samples.sln
# Run in interactive mode (no arguments)
dotnet run --project src/InteractiveUI.Sample.Demo
# Run in CLI mode (with arguments)
dotnet run --project src/InteractiveUI.Sample.Demo -- list -d . -r
dotnet run --project src/InteractiveUI.Sample.Demo -- search -t "ICommand" -d src
dotnet run --project src/InteractiveUI.Sample.Demo -- count -d src -n 10dotnet publish src/InteractiveUI.Sample.Demo -c Release -o publish
./publish/InteractiveUI.Sample.Demo.exeMain class providing interactive menu functionality.
// Create from verb types
public static InteractiveUIBuilder CreateFrom<T1, T2, T3>()
where T1 : class
where T2 : class
where T3 : class
// Run the interactive UI
public void Run()Fluent builder for configuration.
// Configure command executor
public InteractiveUIBuilder WithParser(ICommandLineParser parser)
// Build the UI instance
public InteractiveUI Build()Extension methods for CommandLineParser's Parser class.
public static InteractiveUI WithInteractiveUI<T1, T2, T3>(this Parser parser)
where T1 : class
where T2 : class
where T3 : classInterface for command execution.
public interface ICommandLineParser
{
int Execute(string[] args);
}For detailed API documentation, see CommandLineParser.InteractiveUI/README.md
- Metadata Extraction: Uses reflection to scan assemblies for
[Verb]and[Option]attributes - Dynamic Menu Generation: Builds interactive menus from extracted metadata
- Type-Aware Input: Prompts users with appropriate inputs based on option types:
- Boolean options: Yes/No menu
- String/numeric options: Text input with validation
- Required options: Enforced validation
- Command Construction: Assembles user inputs into argument arrays
- Execution: Passes arguments to your
ICommandLineParserfor execution
- π¨ Colored Headers - Cyan headers with command names and descriptions
- π’ Numbered Menus - Easy numeric selection
- π€ Smart Prompts - Context-aware input based on types
- β Validation - Required field enforcement with clear error messages
- π‘ Default Value Hints - Shows defaults for optional parameters
- π Execution Summary - Reviews complete command before running
- βοΈ Confirmation Prompts - Optional confirmation before execution
- π― Color-Coded Results - Success (green) and error (red) reporting
- π‘οΈ Safe Console Handling - Graceful degradation when console features unavailable
Build applications that support both traditional CLI and interactive modes:
class Program
{
static int Main(string[] args)
{
var executor = new MyCommandExecutor();
// CLI mode: execute immediately with provided arguments
if (args.Length > 0)
{
Console.WriteLine("Running in CLI mode...");
return executor.Execute(args);
}
// Interactive mode: show menus for user-friendly input
Console.WriteLine("Launching interactive mode...\n");
var ui = InteractiveUI.CreateFrom<Verb1, Verb2, Verb3>()
.WithParser(executor)
.Build();
ui.Run();
return 0;
}
}This pattern provides:
- Automation Support - Scripts can pass arguments for non-interactive execution
- User-Friendly Manual Use - Interactive menus for occasional users
- Single Codebase - Same command implementations serve both modes
- Consistent Behavior - Both modes use the same CommandLineParser validation
Make your UI self-documenting:
[Verb("process", HelpText = "Process files with advanced options.")]
public class ProcessOptions
{
[Option('i', "input", Required = true,
HelpText = "Input file path to process.")]
public string Input { get; set; } = "";
}Improve user experience with defaults:
[Option('t', "timeout", Required = false, Default = 30,
HelpText = "Timeout in seconds (default: 30).")]
public int Timeout { get; set; } = 30;Handle errors gracefully in your executor:
private int ExecuteCommand(MyOptions opts)
{
try
{
// Command logic
return 0;
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Error: {ex.Message}");
Console.ResetColor();
return 1;
}
}- β Reusable - Use in any project that uses CommandLineParser
- β Zero Code Generation - Pure runtime reflection
- β Non-Invasive - Extends existing CommandLineParser usage
- β Type-Safe - Leverages CommandLineParser's type system
- β Testable - Clean separation of concerns
- β Clean Architecture - Proper separation of concerns
- β Compile-Time Safety - Dependencies enforced by project references
- β Modular - Commands and options in separate projects
- β Extensible - Easy to add new commands
- .NET 9.0 or higher
- CommandLineParser library (NuGet package)
- DevOps Tools - Build tools that work in CI/CD (CLI) and manual use (Interactive)
- File Management - Create file operation tools with guided workflows
- Database Tools - Database migration/query tools with safe interactive prompts
- Build Utilities - Build systems with both automated and manual modes
- Admin Tools - System administration tools with guided wizards
Contributions are welcome! When contributing:
-
Work on the appropriate solution:
- Library changes β
InteractiveUI.sln - Sample/demo changes β
InteractiveUI.Samples.sln
- Library changes β
-
Ensure code follows existing patterns
-
Update documentation as needed
-
Test both CLI and interactive modes
See License.md for license information.
- STRUCTURE.md - Detailed repository structure
- CommandLineParser.InteractiveUI/README.md - Library API documentation
- CommandLineParser - The excellent CLI parsing library this extends