dotnet / dotnet/command-line-api

Complex object binding sends in null if any argument is evaluates to null (even w/ default)

オープン
#652 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Area-Parser and Binder
主要言語
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;
        }
    }

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、提供されている Program の例を TestRequest、TestCommand、CommandHandler.Create とともに実行し、null バインディングの動作を再現します。複雑なオブジェクトのバインディング経路を調査し、欠落した引数とデフォルト値が null の引数に対するリグレッションテストのカバレッジを追加します。完了には、入力を拒否するか、デフォルトの引数値でリクエストを構築するかという、合意された動作が必要です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
csharp
領域
cli
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。