Spectre.Console 0.47.0: Command Usability Validation
Spectre.Console 0.47.0: Command Usability Validation
Spectre.Console 0.47.0 delivers a comprehensive set of improvements focused on making command-line applications more user-friendly and developer-friendly. This release introduces enhanced validation, better type conversion, improved command organization, and numerous quality-of-life improvements that make building robust CLI applications easier than ever.
What's New in 0.47.0
Enhanced Command Organization
Command structure and navigation received major improvements:
- Command branch aliases allowing multiple names for the same command branch (Ilya Hryapko)
- Default command descriptions with support for custom data and metadata (Cédric Luthi)
- Improved command line parsing with better error handling and user feedback (Frank Ray)
- Example arguments using params syntax for cleaner command documentation (Andrii Rublov)
Advanced Type Conversion Support
Type handling in commands has been significantly enhanced:
- FileInfo and DirectoryInfo conversion for file system operations (Cédric Luthi)
- Array support in DefaultValue attributes for complex default values (Cédric Luthi)
- Better conversion error messages providing clear guidance to users (Cédric Luthi)
- Improved type validation across all supported parameter types
Enhanced Confirmation and Input Handling
User input handling received major improvements:
- Case-insensitive confirmation prompts with configurable string comparers (Martin Zikmund)
- Flexible comparison options for text prompts and confirmations (Martin Zikmund)
- Better input validation with clearer error messages
- Consistent comparer usage across all prompt types
Style and Design System Improvements
Visual consistency and styling capabilities were enhanced:
- Implicit Color to Style conversion simplifying styling code (Cédric Luthi)
- Alignment and justification documentation fixes for better clarity (Will Baldoumas)
- Consistent terminology across documentation and APIs
Developer Experience Enhancements
The development workflow received significant attention:
- Enhanced analyzer support with better compilation checks (Gérald Barré)
- Static lambda and delegate support in analyzers (Gérald Barré)
- Top-level statement compatibility for modern C# patterns (Gérald Barré)
- Improved code fix robustness for better IDE integration (Gérald Barré)
Terminal Compatibility
- Alacritty terminal support added to the list of supported ANSI consoles (MaxAtoms)
- Enhanced ANSI detection for better cross-platform compatibility
- Improved rendering on various terminal emulators
Code Quality and Performance
- StringComparison.Ordinal usage replacing culture-sensitive comparisons for better performance (Gérald Barré)
- Symbol equality optimization in analyzers (Gérald Barré)
- CancellationToken forwarding for better async operation support (Gérald Barré)
- Minor refactoring for improved maintainability (Elisha Aguilera)
Breaking Changes
This release maintains backward compatibility while introducing new capabilities:
- Confirmation prompts now support case-insensitive comparisons (opt-in)
- Command aliases extend existing functionality without breaking changes
- Type conversion enhancements are additive to existing capabilities
Key Contributors
Outstanding contributions from the community:
- Frank Ray: Command-line parsing improvements and enhanced user experience
- Cédric Luthi: Type conversion, validation, and error message enhancements
- Martin Zikmund: Confirmation prompt flexibility and comparer support
- Gérald Barré: Analyzer improvements and performance optimizations
- Ilya Hryapko: Command branch aliasing functionality
- Will Baldoumas: Documentation clarity improvements
- Andrii Rublov: Enhanced example argument syntax
- Patrik Svensson: Release coordination and core improvements
Real-World Examples
Command Branch Aliases
app.Configure(config =>
{
config.AddBranch("database", db =>
{
db.SetAlias("db"); // Short alias for convenience
db.AddCommand<MigrateCommand>("migrate");
});
});
// Both work: "myapp database migrate" and "myapp db migrate"
Enhanced Type Conversion
public class ProcessCommand : Command<ProcessCommand.Settings>
{
public class Settings : CommandSettings
{
[CommandArgument(0, "<input>")]
public FileInfo InputFile { get; set; } = null!; // Automatic conversion
[CommandOption("--output-dir")]
public DirectoryInfo? OutputDirectory { get; set; }
[CommandOption("--formats")]
[DefaultValue(new[] { "json", "xml" })] // Array defaults now supported
public string[] Formats { get; set; } = null!;
}
}
Case-Insensitive Confirmations
var confirmed = AnsiConsole.Prompt(
new ConfirmationPrompt("Delete all files?")
.WithComparer(StringComparer.OrdinalIgnoreCase)); // "Y", "y", "YES", "yes" all work
Improved Error Messages
// Better error messages for invalid inputs
[CommandArgument(0, "<port>")]
[Range(1, 65535)]
public int Port { get; set; }
// Error: "Invalid value for port: 'abc'. Expected a number between 1 and 65535."
Performance Improvements
- Reduced string allocations in command parsing
- Optimized comparison operations using ordinal comparisons
- Enhanced analyzer performance with better symbol handling
- Improved memory usage in prompt scenarios
Get Started
Update your package reference:
<PackageReference Include="Spectre.Console" Version="0.47.0" />
This release significantly improves the developer and user experience for CLI applications while maintaining full backward compatibility with existing code.
Migration Recommendations
While no breaking changes exist, consider these improvements:
- File system commands: Upgrade string parameters to
FileInfo/DirectoryInfofor better validation - Confirmation prompts: Add case-insensitive comparers for better user experience
- Command organization: Use aliases for commonly used command branches
- Default values: Leverage array support for complex default configurations
Community Impact
Version 0.47.0 showcases the strength of the Spectre.Console community with contributions spanning usability, performance, and developer experience. The focus on command-line interface improvements makes this release particularly valuable for developers building production CLI applications.
Looking Ahead
This release establishes excellent groundwork for future enhancements, with robust type conversion, flexible validation, and improved command organization providing a solid foundation for more advanced features in upcoming versions.
Released on May 14, 2023