Help text after failure should go to standard error
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
Research direction
Reproduce the command shown in the issue and compare stdout and stderr when the required --ok option is omitted, including with 2>/dev/null. Done means validation-triggered help follows the error to stderr, while help explicitly requested with -h remains on stdout.
Written by the indexing model from the issue text.
Description
When emitting help text because a command's options weren't specified correctly, the help text should be printed to the standard error stream. This avoids mixing diagnostic messages with program output.
The error message is correctly written to stderr, but the help text is not and I think it should match the error message's behavior.
If help was explicitly asked for with -h, then it's probably okay to send that to standard output.
$ dotnet --version
10.0.301
$ cat ok.cs
#!/usr/bin/env dotnet
#:package [email protected]
using System.CommandLine;
var okOption = new Option<bool>("--ok")
{
Description = "Required flag. When passed, the app prints \"ok\".",
Required = true,
};
var rootCommand = new RootCommand("Prints \"ok\" when --ok is passed.")
{
okOption,
};
rootCommand.Validators.Add(result =>
{
if (result.GetResult(okOption) is null)
{
result.AddError($"Option '{okOption.Name}' is required.");
}
});
rootCommand.SetAction(parseResult =>
{
Console.WriteLine("ok");
return 0;
});
return rootCommand.Parse(args).Invoke();
$ dotnet run ok.cs
Option '--ok' is required.
Description:
Prints "ok" when --ok is passed.
Usage:
ok [options]
Options:
--ok (REQUIRED) Required flag. When passed, the app prints "ok".
-?, -h, --help Show help and usage information
--version Show version information
But redirecting stderr to /dev/null shows that the help text (but not the error message) is printed to stdout:
$ dotnet run ok.cs 2> /dev/null
Description:
Prints "ok" when --ok is passed.
Usage:
ok [options]
Options:
--ok (REQUIRED) Required flag. When passed, the app prints "ok".
-?, -h, --help Show help and usage information
--version Show version information
- Dominant language
- C#
- Stars
- 3.7k
- Forks
- 432
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/command-line-api
-
German localization is incompletePossibly taken @b-v-d-e-v claimed this 2 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
dotnet/command-line-api#2852 ·
-
Incomplete French (fr) translation: RequiredOptionWasNotProvided not translatedPossibly taken @JPBlanc claimed this 100 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
dotnet/command-line-api#2822 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
dotnet/command-line-api#2792 · 2 comments · 15 reactions ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
dotnet/command-line-api#2704 ·
-
GetCompletions should check exit code of invoked applicationPossibly taken @baradgur claimed this 1271 days ago. OpenArea-Completions bug help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
dotnet/command-line-api#2137 · 1 comment · 3 reactions ·
All issues in dotnet/command-line-api
Similar issues
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
VS Code
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
AlamoEngine-Tools/pg-starwarsgame-lsp#207 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
elsa-workflows/elsa-core#8593 ·
Maintainers usually reply within 1 day
-
GpioController.QueryComponentInformation() throws NotSupportedException with RaspberryPi3DriverOpenuntriaged
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
WebSocket upgrade check is case-sensitive for `Upgrade`Possibly taken @S0CloseYetS0Far claimed this today. Openbug good first issue severity:low
Difficulty 1/5 Under an hour Newbie friendliness 88/100