|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/claude-code) when working with this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +**McMaster.Extensions.CommandLineUtils** is a .NET library for building command-line applications. It simplifies parsing command-line arguments, validating user inputs, and generating help text. This is a fork of Microsoft.Extensions.CommandLineUtils. |
| 8 | + |
| 9 | +- **Package:** `McMaster.Extensions.CommandLineUtils` on NuGet |
| 10 | +- **Targets:** .NET 6.0+ |
| 11 | +- **Status:** Stable/maintenance mode (no major features planned) |
| 12 | +- **License:** Apache 2.0 |
| 13 | + |
| 14 | +## Build Commands |
| 15 | + |
| 16 | +```bash |
| 17 | +# Full build with tests (recommended) |
| 18 | +./build.ps1 |
| 19 | + |
| 20 | +# CI mode (enforces formatting checks) |
| 21 | +./build.ps1 -ci |
| 22 | + |
| 23 | +# Build only |
| 24 | +dotnet build |
| 25 | + |
| 26 | +# Run tests |
| 27 | +dotnet test |
| 28 | + |
| 29 | +# Build sample projects |
| 30 | +dotnet build docs/samples/samples.sln |
| 31 | + |
| 32 | +# Generate documentation locally |
| 33 | +./docs/generate.ps1 |
| 34 | +./docs/generate.ps1 -Serve # with local preview |
| 35 | +``` |
| 36 | + |
| 37 | +Build outputs (NuGet packages) go to `/artifacts/`. |
| 38 | + |
| 39 | +## Project Structure |
| 40 | + |
| 41 | +``` |
| 42 | +src/ |
| 43 | + CommandLineUtils/ # Main library |
| 44 | + Attributes/ # Attribute-based API ([Option], [Argument], etc.) |
| 45 | + Conventions/ # Convention system for processing attributes |
| 46 | + Validation/ # Validation framework |
| 47 | + IO/ # Console I/O abstractions (IConsole) |
| 48 | + HelpText/ # Help text generation |
| 49 | + Internal/ # Parsing engine, value parsers |
| 50 | + Utilities/ # ArgumentEscaper, Prompt, DotNetExe |
| 51 | + Hosting.CommandLine/ # Microsoft.Extensions.Hosting integration |
| 52 | +
|
| 53 | +test/ |
| 54 | + CommandLineUtils.Tests/ # xUnit tests for main library |
| 55 | + Hosting.CommandLine.Tests/ # xUnit tests for hosting package |
| 56 | +
|
| 57 | +docs/ |
| 58 | + samples/ # 20+ example projects demonstrating various patterns |
| 59 | +``` |
| 60 | + |
| 61 | +## Two APIs |
| 62 | + |
| 63 | +**1. Attribute-based API:** |
| 64 | +```csharp |
| 65 | +public class Program |
| 66 | +{ |
| 67 | + public static int Main(string[] args) |
| 68 | + => CommandLineApplication.Execute<Program>(args); |
| 69 | + |
| 70 | + [Option(Description = "The subject")] |
| 71 | + public string Subject { get; } = "world"; |
| 72 | + |
| 73 | + private void OnExecute() { /* command logic */ } |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +**2. Builder API:** |
| 78 | +```csharp |
| 79 | +var app = new CommandLineApplication(); |
| 80 | +app.HelpOption(); |
| 81 | +var subject = app.Option("-s|--subject <SUBJECT>", "desc", CommandOptionType.SingleValue); |
| 82 | +app.OnExecute(() => { /* command logic */ }); |
| 83 | +return app.Execute(args); |
| 84 | +``` |
| 85 | + |
| 86 | +## Key Patterns |
| 87 | + |
| 88 | +- **Conventions:** Extensible `IConvention` implementations process attributes and wire up behavior |
| 89 | +- **Validation:** Three approaches - attribute validators (`[Required]`, `[FileExists]`), fluent API (`.IsRequired()`, `.Accepts()`), and `OnValidate()` methods |
| 90 | +- **Console abstraction:** `IConsole` interface enables testing; use `PhysicalConsole` for real I/O |
| 91 | +- **Response files:** Support for `@filename` syntax to read arguments from files |
| 92 | + |
| 93 | +## Code Style |
| 94 | + |
| 95 | +- 4-space indentation |
| 96 | +- Nullable reference types enabled |
| 97 | +- Warnings treated as errors |
| 98 | +- Code style enforced in build (`EnforceCodeStyleInBuild=true`) |
| 99 | +- Format check: `dotnet tool run dotnet-format` |
| 100 | + |
| 101 | +## Testing |
| 102 | + |
| 103 | +Uses xUnit with FluentAssertions and Moq. Convention tests inherit from `ConventionTestBase` and use `Create<T>()` factory method. |
| 104 | + |
| 105 | +```bash |
| 106 | +dotnet test --collect:"XPlat Code Coverage" |
| 107 | +``` |
0 commit comments