CommandLine.Readme
1.0.1
dotnet add package CommandLine.Readme --version 1.0.1
NuGet\Install-Package CommandLine.Readme -Version 1.0.1
<PackageReference Include="CommandLine.Readme" Version="1.0.1" />
<PackageVersion Include="CommandLine.Readme" Version="1.0.1" />
<PackageReference Include="CommandLine.Readme" />
paket add CommandLine.Readme --version 1.0.1
#r "nuget: CommandLine.Readme, 1.0.1"
#:package CommandLine.Readme@1.0.1
#addin nuget:?package=CommandLine.Readme&version=1.0.1
#tool nuget:?package=CommandLine.Readme&version=1.0.1
System.CommandLine.Readme
System.CommandLine.Readme is an extension library for System.CommandLine that automatically generates professional README documentation in Markdown format from your command-line interface configuration.
๐ฏ Features
- Automatic Documentation Generation: Creates comprehensive markdown documentation from your CLI configuration
- Complete Coverage: Documents commands, subcommands, options, arguments, aliases, and descriptions
- Hierarchical Structure: Properly formatted nested command structures with appropriate indentation
- Markdown Formatting: Professional markdown output with headings, bold text, code blocks, and tables
- Easy Integration: Single line of code to add README generation capability
- Type Information: Includes value types and required flags for options and arguments
- Extensible: Built with internal formatting helpers for easy customization
๐ฆ Installation
Install the package via NuGet:
dotnet add package CommandLine.Readme
Or using the Package Manager Console:
Install-Package CommandLine.Readme
๐ Quick Start
Basic Usage
- Add the extension to your RootCommand:
using System.CommandLine;
using System.CommandLine.Readme;
var rootCommand = new RootCommand("My awesome CLI application");
var option = new Option<string>("--config", "Configuration file path");
rootCommand.AddOption(option);
// Add README generation capability
rootCommand.AddCommandLineReadmeToRoot();
return await rootCommand.InvokeAsync(args);
- Generate the README file:
# Using the full command and option names
myapp readme --readme-file README.md
# Using aliases (shorter form)
myapp rm -md README.md
- Done! Your
README.mdfile is now generated with complete documentation of your CLI.
๐ Detailed Usage
Advanced Example
using System.CommandLine;
using System.CommandLine.Readme;
var rootCommand = new RootCommand("Advanced CLI application for data processing");
// Add global options
var verboseOption = new Option<bool>(
"--verbose",
"Enable verbose logging");
verboseOption.AddAlias("-v");
rootCommand.AddOption(verboseOption);
// Add a subcommand
var processCommand = new Command("process", "Process data files");
var inputOption = new Option<FileInfo>(
"--input",
"Input file to process")
{
IsRequired = true
};
inputOption.AddAlias("-i");
var outputOption = new Option<FileInfo>(
"--output",
"Output file path");
outputOption.AddAlias("-o");
processCommand.AddOption(inputOption);
processCommand.AddOption(outputOption);
// Add argument to subcommand
var formatArgument = new Argument<string>(
"format",
"Output format (json, xml, csv)");
processCommand.AddArgument(formatArgument);
rootCommand.AddCommand(processCommand);
// Enable README generation
rootCommand.AddCommandLineReadmeToRoot();
return await rootCommand.InvokeAsync(args);
Generated Output
The above example will generate a well-structured markdown file containing:
- Application name as main heading
- Horizontal separators for visual organization
- Root command description and options
- All subcommands with their options and arguments
- Aliases for commands and options
- Required flags for mandatory options
- Type information for all options and arguments
- Proper hierarchical structure with indentation
Example Generated Markdown:
# myapp
---
## **myapp**: *Advanced CLI application for data processing*
## **myapp** options
### **--verbose**: *Enable verbose logging*
Aliases: `-v`
ValueType=*System.Boolean*
## **myapp** subcommands
* ### **process**: *Process data files*
Aliases: `process`
* #### **process** options
* ##### **--input**: *Input file to process*
Aliases: `-i`
***IsRequired;***
ValueType=*System.IO.FileInfo*
* ##### **--output**: *Output file path*
Aliases: `-o`
ValueType=*System.IO.FileInfo*
* #### **process** arguments:
##### format : Output format (json, xml, csv)
๐ง API Reference
Extension Methods
AddCommandLineReadmeToRoot(this RootCommand rootCommand)
Adds a readme command (alias: rm) to your root command with a --readme-file option (alias: -md).
Example:
rootCommand.AddCommandLineReadmeToRoot();
Static Methods
CreateMarkDown.CreateReadme(RootCommand rootCommand)
Generates markdown documentation as a string from the provided RootCommand.
Parameters:
rootCommand: The RootCommand to document
Returns: string - The generated markdown content
Example:
string markdown = CreateMarkDown.CreateReadme(rootCommand);
Console.WriteLine(markdown);
CreateMarkDown.CreateReadmeFile(RootCommand rootCommand, string path)
Generates and saves markdown documentation directly to a file.
Parameters:
rootCommand: The RootCommand to documentpath: The file path where the README should be saved
Example:
CreateMarkDown.CreateReadmeFile(rootCommand, "docs/CLI.md");
๐ Markdown Features
The library includes comprehensive markdown formatting capabilities through internal helpers:
- Headings (levels 1-6)
- Text Formatting: Bold, Italic, Bold+Italic
- Code: Inline code and code blocks (with language specification)
- Lists: Ordered, unordered, and nested lists
- Blockquotes: Single and nested
- Tables: Full table support with headers
- Links: Markdown-style hyperlinks
- Horizontal Rules
- Tabs and Indentation: For hierarchical structures
๐๏ธ Architecture
The library is organized into three main components:
CreateMarkDown (Public API)
The main entry point providing:
CreateReadme(RootCommand)- Generates markdown stringCreateReadmeFile(RootCommand, string)- Generates and saves to fileAddCommandLineReadmeToRoot()- Extension method for CLI integration
CommandFormatHelper (Internal)
Handles System.CommandLine-specific formatting:
FormatRootCommand()- Formats the root command with all its componentsFormatCommand()- Formats individual commands recursivelyFormatOptions()- Formats options with type info and required flagsFormatAliases()- Formats command/option aliasesFormatSymbols()- Generic symbol formatting
MarkdownFormatHelper (Internal)
Provides 20+ markdown formatting extension methods:
- Text styling (bold, italic, code)
- Structure (headings, lists, tables)
- Special elements (blockquotes, links, horizontal rules)
- Layout (tabs, indentation, line breaks)
All internal classes are exposed to the test assembly via InternalsVisibleTo attribute for comprehensive testing.
๐งช Testing
The library includes a comprehensive test suite with 130+ unit tests covering:
- MarkdownFormatHelperTests (82 tests) - All markdown formatting extension methods
- CommandFormatHelperTests (30 tests) - Command-line formatting logic
- CreateMarkDownTests (18 tests) - README generation functionality
Test Coverage Includes:
- Happy path scenarios
- Edge cases (null values, empty strings, boundary conditions)
- Integration tests (file I/O, command invocation)
- API correctness validation
Running Tests
Run all tests:
dotnet test
Run tests with detailed output:
dotnet test --logger:"console;verbosity=detailed"
Run specific test class:
dotnet test --filter "FullyQualifiedName~MarkdownFormatHelperTests"
Run with code coverage:
dotnet test /p:CollectCoverage=true
๐ ๏ธ Requirements
Runtime Requirements
- .NET Standard 2.0 or higher
- Compatible with .NET Framework 4.6.1+
- Compatible with .NET Core 2.0+
- Compatible with .NET 5.0+
- Compatible with .NET 6.0+
- Compatible with .NET 7.0+
- Compatible with .NET 8.0+
Dependencies
- System.CommandLine (2.0.0-beta4.22272.1 or compatible)
- The library this package extends
Development Dependencies (Optional)
- StyleCop.Analyzers (1.2.0-beta.556) - For code quality analysis (Debug builds only)
๐ก Best Practices
Writing Good Descriptions
- Be concise: Keep command and option descriptions to one sentence when possible
- Be specific: Clearly state what the command/option does
- Use imperative mood: "Process files" instead of "Processes files"
Command Structure
// โ
Good: Clear hierarchy
var rootCommand = new RootCommand("Application description");
var processCommand = new Command("process", "Process data files");
rootCommand.AddCommand(processCommand);
// โ Avoid: Too many levels of nesting (hard to read in documentation)
Option Naming
// โ
Good: Consistent naming with clear aliases
var option = new Option<string>("--output-file", "Output file path");
option.AddAlias("-o");
// โ
Good: Mark critical options as required
var inputOption = new Option<FileInfo>("--input", "Input file")
{
IsRequired = true
};
Documentation Workflow
- Develop your CLI: Focus on functionality first
- Add descriptions: Write clear descriptions for all commands/options
- Add README generation: Call
AddCommandLineReadmeToRoot() - Generate documentation: Run
myapp readme --readme-file README.md - Review and commit: Include the generated README in your repository
- Keep in sync: Regenerate the README whenever you add/modify CLI commands
CI/CD Integration
# Add to your build/test pipeline to ensure README stays up-to-date
dotnet run -- readme --readme-file README.md
git diff --exit-code README.md || (echo "README is out of date!" && exit 1)
๐ Use Cases
- Open Source Projects: Automatically keep your CLI documentation in sync with code
- Internal Tools: Generate documentation for corporate CLI tools
- API Clients: Document CLI wrappers for web services
- DevOps Tools: Create self-documenting deployment and automation scripts
- Educational Projects: Help users understand available commands and options
๐ Troubleshooting
Common Issues
Q: The readme command is not available in my CLI
A: Make sure you've called rootCommand.AddCommandLineReadmeToRoot() before invoking the command.
Q: The generated README is missing some commands/options
A: Ensure all commands and options are added to the RootCommand before generating the README. The library can only document what's been configured.
Q: I get a "file already exists" error
A: The library overwrites existing files by default. Ensure you have write permissions to the target directory.
Q: How do I customize the output format?
A: Currently, the library uses a fixed format optimized for CLI documentation. For custom formatting, you can use CreateMarkDown.CreateReadme() to get the markdown string and modify it programmatically.
Q: Can I use this with System.CommandLine 1.x?
A: This library is designed for System.CommandLine 2.0+. It may not work correctly with version 1.x due to API changes.
๐ค Contributing
Contributions are welcome! This project follows standard contribution guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Add tests for new functionality (maintain 100% coverage)
- Ensure all tests pass (
dotnet test) - Follow coding standards (StyleCop analyzers are enabled)
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Setup
# Clone the repository
git clone <repository-url>
cd System.CommandLine.Readme/src
# Restore dependencies
dotnet restore
# Build the project
dotnet build
# Run tests
dotnet test
# Run tests with coverage
dotnet test /p:CollectCoverage=true
Code Quality
- All public APIs must have XML documentation comments
- Follow existing code style and patterns
- Internal helpers should be tested via
InternalsVisibleTo - Use FluentAssertions for test assertions
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
Built as an extension for System.CommandLine by Microsoft.
๐ Support
For issues, questions, or suggestions:
- Open an issue on the project repository
- Check existing documentation and tests for examples
๐ Version History
- 0.1.1-release: Current stable version
- Comprehensive markdown generation
- Support for commands, options, arguments
- Alias documentation
- Type information display
- Required flags
Made with โค๏ธ by Vita7y | Copyright ยฉ 2025
| 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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
- System.CommandLine (>= 2.0.1)
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 |
|---|---|---|
| 1.0.1 | 148 | 12/31/2025 |
| 1.0.0-release | 117 | 12/31/2025 |
| 0.2.1-release | 115 | 12/30/2025 |
| 0.1.1-release | 441 | 9/7/2024 |