|
| 1 | +# Migration Guide — 2.0 |
| 2 | + |
| 3 | +This guide summarizes the 2.0 API changes that require code updates. |
| 4 | + |
| 5 | +## Breaking Renames |
| 6 | + |
| 7 | +| 1.x | 2.0 | |
| 8 | +|---|---| |
| 9 | +| `OptionException` | `CommandOptionException` | |
| 10 | +| `CommandNode.IsThisNodeActive` | `CommandNode.ActivePredicate` | |
| 11 | +| `Command.OptionsName` | `Command.OptionsSectionName` | |
| 12 | + |
| 13 | +## `ICommandOutput` Unknown Token API |
| 14 | + |
| 15 | +`WriteUnknownTokens` now receives a single report object: |
| 16 | + |
| 17 | +```csharp |
| 18 | +void WriteUnknownTokens(Command command, CommandRunConfig runConfig, UnknownTokenReport report); |
| 19 | +``` |
| 20 | + |
| 21 | +`UnknownTokenReport` includes: |
| 22 | +- `Kind` |
| 23 | +- `UnknownTokens` |
| 24 | +- `InvocationTokens` (when available) |
| 25 | + |
| 26 | +Update custom outputs to use `report.Kind`, `report.UnknownTokens`, and `report.InvocationTokens`. |
| 27 | + |
| 28 | +## Metadata Mutability Changes |
| 29 | + |
| 30 | +These members now use construction-time initialization: |
| 31 | + |
| 32 | +- `Command.Hidden` (`init`) |
| 33 | +- `Command.OptionsSectionName` (`init`) |
| 34 | +- `Option.EnvironmentVariable` (`init`) |
| 35 | +- `Option.EnvironmentVariableDelimiter` (`init`) |
| 36 | + |
| 37 | +### Before |
| 38 | + |
| 39 | +```csharp |
| 40 | +var hidden = new Command("secret"); |
| 41 | +hidden.Hidden = true; |
| 42 | + |
| 43 | +app.Options["name"].EnvironmentVariable = "APP_NAME"; |
| 44 | +``` |
| 45 | + |
| 46 | +### After |
| 47 | + |
| 48 | +```csharp |
| 49 | +var hidden = new Command("secret") |
| 50 | +{ |
| 51 | + Hidden = true |
| 52 | +}; |
| 53 | + |
| 54 | +app.Add("n|name=", "Name", value => { }, envVar: "APP_NAME"); |
| 55 | +``` |
| 56 | + |
| 57 | +## New Clarity Helpers |
| 58 | + |
| 59 | +The following helpers were added to reduce overload ambiguity and improve intent: |
| 60 | + |
| 61 | +- `AddRemainder(string? description = null)` |
| 62 | +- `AddText(string text)` |
| 63 | +- `AddSection(string header)` (auto-appends `:` when missing) |
| 64 | + |
| 65 | +## Overload Parity Additions |
| 66 | + |
| 67 | +Typed and list families now support `hidden` parity: |
| 68 | + |
| 69 | +- `Add<T>(..., Action<T> action, bool hidden)` |
| 70 | +- `Add<T>(..., ICollection<T> list, bool hidden)` |
| 71 | +- Validation and env-var variants with `hidden` support are available for typed/list overloads. |
| 72 | + |
| 73 | +## Notes |
| 74 | + |
| 75 | +- Key/value (`Action<TKey, TValue>`) overloads intentionally still do **not** support env-var fallback or validation delegates. |
| 76 | +- Command graphs remain single-invocation-at-a-time; avoid concurrent `RunAsync`/`Parse` on the same graph instance. |
0 commit comments