Skip to content

Commit c7199e7

Browse files
committed
Use positional Add args in markdown examples (Fixes #1)
1 parent 812df1b commit c7199e7

16 files changed

+2200
-123
lines changed

readme.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939

4040
## 🧪 Example
4141

42-
```csharp
42+
<!-- snippet: readme_md_001 -->
43+
```cs
4344
using System;
4445
using XenoAtom.CommandLine;
4546

@@ -107,6 +108,7 @@ var commandApp = new CommandApp("myexe")
107108

108109
await commandApp.RunAsync(args);
109110
```
111+
<!-- endSnippet -->
110112

111113
Notes:
112114
- `CommandUsage()` defaults to `Usage: {NAME} {SYNTAX}` and `{SYNTAX}` is derived from your declared options/commands/arguments.
@@ -167,7 +169,8 @@ Commit message: World!
167169

168170
For richer CLI output, use the optional `XenoAtom.CommandLine.Terminal` package:
169171

170-
```csharp
172+
<!-- snippet: readme_md_002 -->
173+
```cs
171174
using XenoAtom.CommandLine;
172175
using XenoAtom.CommandLine.Terminal;
173176
using XenoAtom.Terminal.UI;
@@ -203,6 +206,7 @@ var app = new CommandApp("myexe", config: new CommandConfig
203206
(ctx, _) => ValueTask.FromResult(0)
204207
};
205208
```
209+
<!-- endSnippet -->
206210

207211
This package also provides `command.ToHelpVisual(...)` for embedding help in Terminal.UI apps.
208212
For one-shot rendering, `Terminal.Write(...)` is lazily initialized and does not require an explicit terminal session.

site/docs/advanced.md

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ This guide covers advanced features of XenoAtom.CommandLine: the parse API for t
1010

1111
`CommandApp.Parse(...)` runs the full parsing pipeline — option callbacks, argument binding, constraint checks — but **does not** invoke the command action. This is ideal for unit testing:
1212

13-
```csharp
13+
<!-- snippet: site_docs_advanced_md_001 -->
14+
```cs
1415
string? name = null;
1516
int port = 0;
1617

@@ -31,6 +32,7 @@ var result = app.Parse(["--name", "Alice", "--port", "8080"]);
3132
// name → "Alice" (option callbacks are invoked)
3233
// port → 8080
3334
```
35+
<!-- endSnippet -->
3436

3537
### ParseResult Properties
3638

@@ -64,12 +66,14 @@ var result = app.Parse(["--name", "Alice", "--port", "8080"]);
6466

6567
### Testing Sub-Commands
6668

67-
```csharp
69+
<!-- snippet: site_docs_advanced_md_002 -->
70+
```cs
6871
var result = app.Parse(["commit", "--message", "Hello"]);
6972

7073
// result.ResolvedCommandPath → "myexe commit"
7174
// result.OptionValues["message"][0] → "Hello"
7275
```
76+
<!-- endSnippet -->
7377

7478
## Shell Completions
7579

@@ -79,7 +83,8 @@ XenoAtom.CommandLine can generate shell completion scripts and provide completio
7983

8084
Add `CompletionCommands` to your app to expose completion commands:
8185

82-
```csharp
86+
<!-- snippet: site_docs_advanced_md_003 -->
87+
```cs
8388
var app = new CommandApp("myexe")
8489
{
8590
new CompletionCommands(),
@@ -89,6 +94,7 @@ var app = new CommandApp("myexe")
8994
(ctx, _) => ValueTask.FromResult(0)
9095
};
9196
```
97+
<!-- endSnippet -->
9298

9399
This adds two sub-commands:
94100
- `completion <shell>` (hidden) — generates the shell completion script
@@ -118,25 +124,29 @@ myexe completion powershell | Out-String | Invoke-Expression
118124

119125
You can also get completion candidates programmatically:
120126

121-
```csharp
127+
<!-- snippet: site_docs_advanced_md_004 -->
128+
```cs
122129
var candidates = app.GetCompletions("myexe --na");
123130
// → ["--name"]
124131
125-
var candidates = app.GetCompletionsForTokens(["myexe", "buil"], tokenIndex: 1);
132+
var commandCandidates = app.GetCompletionsForTokens(["myexe", "buil"], tokenIndex: 1);
126133
// → ["build"]
127134
```
135+
<!-- endSnippet -->
128136

129137
### Value Completions
130138

131139
Provide completion candidates for option and argument values:
132140

133-
```csharp
141+
<!-- snippet: site_docs_advanced_md_005 -->
142+
```cs
134143
app.Options["name"].ValueCompleter = static (index, prefix) =>
135144
["Alice", "Bob", "Charlie"];
136145

137146
app.Arguments[0].ValueCompleter = static (index, prefix) =>
138147
["README.md", "src/", "tests/"];
139148
```
149+
<!-- endSnippet -->
140150

141151
The `ValueCompleter` delegate receives:
142152
- `index` — the 0-based value index being completed
@@ -159,7 +169,8 @@ Response files let users put arguments in a file and reference it with `@`:
159169

160170
Add `ResponseFileSource` to your command:
161171

162-
```csharp
172+
<!-- snippet: site_docs_advanced_md_006 -->
173+
```cs
163174
var app = new CommandApp("myexe")
164175
{
165176
new HelpOption(),
@@ -173,6 +184,7 @@ var app = new CommandApp("myexe")
173184
}
174185
};
175186
```
187+
<!-- endSnippet -->
176188

177189
Help output includes:
178190

@@ -212,7 +224,8 @@ myexe @args.txt
212224

213225
You can create your own argument source by extending `ArgumentSource`:
214226

215-
```csharp
227+
<!-- snippet: site_docs_advanced_md_007 -->
228+
```cs
216229
public class EnvironmentSource : ArgumentSource
217230
{
218231
public override string Description => "Read arguments from environment";
@@ -230,14 +243,16 @@ public class EnvironmentSource : ArgumentSource
230243
}
231244
}
232245
```
246+
<!-- endSnippet -->
233247

234248
## Configuration
235249

236250
### CommandConfig
237251

238252
`CommandConfig` controls application-level behavior. It is set once when creating the `CommandApp`:
239253

240-
```csharp
254+
<!-- snippet: site_docs_advanced_md_008 -->
255+
```cs
241256
var config = new CommandConfig
242257
{
243258
StrictOptionParsing = true, // default
@@ -248,6 +263,7 @@ var config = new CommandConfig
248263

249264
var app = new CommandApp("myexe", config: config);
250265
```
266+
<!-- endSnippet -->
251267

252268
{.table}
253269
| Property | Default | Description |
@@ -261,7 +277,8 @@ var app = new CommandApp("myexe", config: config);
261277

262278
`CommandRunConfig` controls runtime behavior for a specific invocation:
263279

264-
```csharp
280+
<!-- snippet: site_docs_advanced_md_009 -->
281+
```cs
265282
var runConfig = new CommandRunConfig(Width: 120, OptionWidth: 32)
266283
{
267284
Out = Console.Out,
@@ -271,6 +288,7 @@ var runConfig = new CommandRunConfig(Width: 120, OptionWidth: 32)
271288

272289
await app.RunAsync(args, runConfig);
273290
```
291+
<!-- endSnippet -->
274292

275293
{.table}
276294
| Property | Default | Description |
@@ -285,33 +303,38 @@ await app.RunAsync(args, runConfig);
285303

286304
Use `CommandConfig.Localizer` to translate all built-in strings:
287305

288-
```csharp
306+
<!-- snippet: site_docs_advanced_md_010 -->
307+
```cs
289308
var app = new CommandApp("myexe", config: new CommandConfig
290309
{
291310
Localizer = text => MyLocalizationService.Translate(text),
292311
});
293312
```
313+
<!-- endSnippet -->
294314

295315
The localizer is applied before strings are written to `Out`/`Error`.
296316

297317
### Environment Variable Resolution
298318

299319
Override environment variable lookup for testing or custom scenarios:
300320

301-
```csharp
321+
<!-- snippet: site_docs_advanced_md_011 -->
322+
```cs
302323
var envVars = new Dictionary<string, string> { ["MY_PORT"] = "8080" };
303324

304325
var app = new CommandApp("myexe", config: new CommandConfig
305326
{
306327
EnvironmentVariableResolver = name => envVars.GetValueOrDefault(name),
307328
});
308329
```
330+
<!-- endSnippet -->
309331

310332
## EnumWrapper
311333

312334
`EnumWrapper<T>` provides AOT-friendly enum parsing for options:
313335

314-
```csharp
336+
<!-- snippet: site_docs_advanced_md_012 -->
337+
```cs
315338
var colors = new List<Color>();
316339

317340
var app = new CommandApp("myexe")
@@ -323,6 +346,7 @@ var app = new CommandApp("myexe")
323346

324347
enum Color { Red, Green, Blue }
325348
```
349+
<!-- endSnippet -->
326350

327351
`EnumWrapper<T>`:
328352
- Implements `ISpanParsable<T>` for seamless integration with the option parser.

0 commit comments

Comments
 (0)