From 59f8949093b95aa962dbf9b5ddf012e7e9952e75 Mon Sep 17 00:00:00 2001 From: abhiramch018 Date: Tue, 25 Nov 2025 18:13:38 +0530 Subject: [PATCH] docs: fix System.CommandLine tab-completion example to use RootCommand MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Summary Fixed the tab-completion example in `how-to-enable-tab-completion.md` by updating the sample code to use `RootCommand` instead of `Command`. ### Changes - Wrapped the command in a `RootCommand`. - Updated the invocation to use `rootCommand.Parse(args).InvokeAsync()`. - Verified that tab-completion and help now work correctly. ### Why Resolves issue #48478 — the original code used `.Parse(args).Invoke()` on a `Command`, which prevented tab-completion and help from working as intended. --- .../commandline/snippets/tab-completion/csharp/Program.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/standard/commandline/snippets/tab-completion/csharp/Program.cs b/docs/standard/commandline/snippets/tab-completion/csharp/Program.cs index b7748a7870fce..fa4924528e60e 100644 --- a/docs/standard/commandline/snippets/tab-completion/csharp/Program.cs +++ b/docs/standard/commandline/snippets/tab-completion/csharp/Program.cs @@ -3,7 +3,13 @@ using System.CommandLine.Completions; using System.CommandLine.Parsing; -new DateCommand().Parse(args).Invoke(); +var rootCommand = new RootCommand("Sample app with tab-completion") +{ + new DateCommand() +}; + +await rootCommand.Parse(args).InvokeAsync(); + class DateCommand : Command {