dotnet / dotnet/command-line-api
Complex object binding sends in null if any argument is evaluates to null (even w/ default)
まだ誰も着手していません。
- 主要言語
- C#
- スター
- 3.7k
- フォーク
- 428
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
Hi there, thanks for adding support for complex object binding -- makes the handler code SO much cleaner.
During my refactor to complex, I noticed that whenever a single argument is null w/o a default supplied (or default null), the entire complex type gets passed in as null.
I don't think passing in null would ever be desirable -- either the parser needs to throw or pass in the "default" version of the object (using default(T) for each argument that comes in as null maybe?)
We have plenty of use cases where we allow the user to not provide an input and we pull it from a saved setting.
Here's a working example of the behavior:
class Program
{
static void Main(string[] args)
{
var root = new RootCommand();
root.AddCommand(TestCommand.Instance);
root.InvokeAsync(args).Wait();
}
}
public class TestRequest
{
public TestRequest(string test1)
{
this.Test1 = test1;
}
public string Test1 { get; }
}
public static class TestCommand
{
public static Command Instance = GetTestCommand();
private static Command GetTestCommand()
{
var test = new Command("test");
//broken w/ default null
//test.AddOption(new Option("--test1")
//{
// Argument = new Argument<string>(() => null)
//});
////broken w/o default
//test.AddOption(new Option("--test1")
//{
// Argument = new Argument<string>()
//});
//works w/ empty string
test.AddOption(new Option("--test1")
{
Argument = new Argument<string>(() => "")
});
test.Handler = CommandHandler.Create((TestRequest request) =>
{
var msg = request == null ? "I'm broken!" : "I work!";
Console.WriteLine(msg);
});
return test;
}
}
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提供されている Program の例を TestRequest、TestCommand、CommandHandler.Create とともに実行し、null バインディングの動作を再現します。複雑なオブジェクトのバインディング経路を調査し、欠落した引数とデフォルト値が null の引数に対するリグレッションテストのカバレッジを追加します。完了には、入力を拒否するか、デフォルトの引数値でリクエストを構築するかという、合意された動作が必要です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- csharp
- 領域
- cli
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 30/100