CommandLine.Readme 1.0.1

dotnet add package CommandLine.Readme --version 1.0.1
                    
NuGet\Install-Package CommandLine.Readme -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CommandLine.Readme" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CommandLine.Readme" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="CommandLine.Readme" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CommandLine.Readme --version 1.0.1
                    
#r "nuget: CommandLine.Readme, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CommandLine.Readme@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CommandLine.Readme&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=CommandLine.Readme&version=1.0.1
                    
Install as a Cake Tool

System.CommandLine.Readme

NuGet License: MIT .NET Standard 2.0

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

  1. 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);
  1. 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
  1. Done! Your README.md file 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 document
  • path: 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 string
  • CreateReadmeFile(RootCommand, string) - Generates and saves to file
  • AddCommandLineReadmeToRoot() - Extension method for CLI integration

CommandFormatHelper (Internal)

Handles System.CommandLine-specific formatting:

  • FormatRootCommand() - Formats the root command with all its components
  • FormatCommand() - Formats individual commands recursively
  • FormatOptions() - Formats options with type info and required flags
  • FormatAliases() - Formats command/option aliases
  • FormatSymbols() - 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

  1. Develop your CLI: Focus on functionality first
  2. Add descriptions: Write clear descriptions for all commands/options
  3. Add README generation: Call AddCommandLineReadmeToRoot()
  4. Generate documentation: Run myapp readme --readme-file README.md
  5. Review and commit: Include the generated README in your repository
  6. 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:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Add tests for new functionality (maintain 100% coverage)
  4. Ensure all tests pass (dotnet test)
  5. Follow coding standards (StyleCop analyzers are enabled)
  6. Commit your changes (git commit -m 'Add amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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