If you set an Action on an Option object, it is required to return an integer, but the return value is silently discarded
The problem is on this line, where the return value is discarded.
The following reproduces the problem
using System.CommandLine;
using System.CommandLine.Invocation;
namespace CommandLineTest
{
[TestClass]
public sealed class CommandLineTests
{
[TestMethod]
public void OptionActionReturnValuePropagates()
{
RootCommand root = new("CommandLine Test");
Option<bool> option = new("--arg");
option.Action = new CustomAction(_ => 42);
root.Options.Add(option);
root.SetAction(r => { });
ParseResult parsedArgs = root.Parse(["--arg"]);
int result = parsedArgs.Invoke();
Assert.AreEqual(42, result);
}
class CustomAction : SynchronousCommandLineAction
{
private readonly Func<ParseResult, int> _callback;
internal CustomAction(Func<ParseResult, int> callback) => _callback = callback;
public override int Invoke(ParseResult parseResult) => _callback(parseResult);
public override bool Terminating => false;
}
}
}
If you set an
Actionon anOptionobject, it is required to return an integer, but the return value is silently discardedThe problem is on this line, where the return value is discarded.
The following reproduces the problem