Skip to content

Commit 7bb8491

Browse files
CopilotwaldekmastykarzCopilotgarrytrinder
authored
Improve CLI help text: I/O contract, dynamic commands, config precedence (#1555)
* Initial plan * Improve help text: I/O contract, dynamic commands, config precedence Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com> * Update DevProxy/Commands/DevProxyCommand.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com> Co-authored-by: Waldek Mastykarz <waldek@mastykarz.nl> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Garry Trinder <garry@trinder365.co.uk>
1 parent 10e5863 commit 7bb8491

2 files changed

Lines changed: 52 additions & 5 deletions

File tree

DevProxy/Commands/DevProxyCommand.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ sealed class DevProxyCommand : RootCommand
3030
internal static readonly Option<string?> ConfigFileOption = new(ConfigFileOptionName, "-c")
3131
{
3232
HelpName = "config-file",
33-
Description = "The path to the configuration file"
33+
Description = "Path to config file. If not specified, Dev Proxy searches for devproxyrc.jsonc or devproxyrc.json in the current directory, then in a .devproxy/ directory, then under the ~appFolder location. Supports ~appFolder token."
3434
};
3535
internal const string NoFirstRunOptionName = "--no-first-run";
3636
internal const string NoWatchOptionName = "--no-watch";
@@ -574,13 +574,18 @@ private void ConfigureCommand()
574574
]);
575575
HelpExamples.Install(this);
576576

577+
CustomizeHelp();
578+
579+
SetAction(InvokeAsync);
580+
}
581+
582+
private void CustomizeHelp()
583+
{
577584
var helpOption = Options.OfType<HelpOption>().FirstOrDefault();
578-
if (helpOption?.Action is HelpAction helpAction)
585+
if (helpOption?.Action is SynchronousCommandLineAction currentAction)
579586
{
580-
helpOption.Action = new ExitCodeHelpAction(helpAction);
587+
helpOption.Action = new DevProxyHelpAction(currentAction);
581588
}
582-
583-
SetAction(InvokeAsync);
584589
}
585590

586591
private void ConfigureFromOptions(ParseResult parseResult)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.CommandLine;
6+
using System.CommandLine.Help;
7+
using System.CommandLine.Invocation;
8+
9+
namespace DevProxy.Commands;
10+
11+
sealed class DevProxyHelpAction(SynchronousCommandLineAction originalAction) : SynchronousCommandLineAction
12+
{
13+
public override int Invoke(ParseResult parseResult)
14+
{
15+
originalAction.Invoke(parseResult);
16+
17+
if (parseResult.CommandResult.Command is not RootCommand)
18+
{
19+
return 0;
20+
}
21+
22+
var output = parseResult.Configuration.Output;
23+
24+
output.WriteLine();
25+
output.WriteLine(" Additional commands may be available depending on configured plugins.");
26+
output.WriteLine(" Use -c <config-file> to load a specific configuration.");
27+
output.WriteLine();
28+
output.WriteLine("Output:");
29+
output.WriteLine(" Primary output goes to stdout. Errors and diagnostics go to stderr.");
30+
output.WriteLine(" Use --output json for structured output.");
31+
output.WriteLine();
32+
output.WriteLine("Configuration precedence:");
33+
output.WriteLine(" CLI flags > config file > defaults");
34+
output.WriteLine();
35+
output.WriteLine("Exit codes:");
36+
output.WriteLine(" 0 Success");
37+
output.WriteLine(" 1 Runtime error");
38+
output.WriteLine(" 2 Invalid input or usage");
39+
40+
return 0;
41+
}
42+
}

0 commit comments

Comments
 (0)