예제 #1
0
        public void Options()
        {
            var map = new MapOptions <Simple>();

            var app = new CommandLineApplication();

            app.Option("-d|--debug", "flag", CommandOptionType.NoValue)
            .Map(map, to => to.Debug);

            var result  = app.Parse("-d");
            var builder = new ConfigurationBuilder()
                          .AddCommandLineOptions(map.FromCommand(result.SelectedCommand))
                          .Build();

            var options = new Simple();

            builder.Bind(options);

            options
            .Should()
            .BeEquivalentTo(new Simple
            {
                Debug = true
            });
        }
예제 #2
0
        public void Operands()
        {
            var map = new MapOptions <Simple>();

            var app = new CommandLineApplication();

            app.Argument("files", "Input files", true)
            .Map(map, to => to.Multiple);

            var result  = app.Parse("input1.txt", "input2.txt");
            var builder = new ConfigurationBuilder()
                          .AddCommandLineOptions(map.FromCommand(result.SelectedCommand))
                          .Build();

            var options = new Simple();

            builder.Bind(options);

            options
            .Should()
            .BeEquivalentTo(new Simple
            {
                Multiple = new[] { "input1.txt", "input2.txt" }
            });
        }
예제 #3
0
        public void NotMappedShort()
        {
            var map = new MapOptions <Simple>();

            var app = new CommandLineApplication();

            app.Option("-c",
                       "Input files", CommandOptionType.NoValue);

            var result = app.Parse("-c");

            var builder = new ConfigurationBuilder()
                          .AddCommandLineOptions(map.FromCommand(result.SelectedCommand))
                          .Build();

            var options = new Simple();

            builder.Bind(options);

            options
            .Should()
            .BeEquivalentTo(new Simple
            {
                C = true
            });
        }
예제 #4
0
        public void NotMapped()
        {
            var map = new MapOptions <Simple>();

            var app = new CommandLineApplication();

            app.Option("-m|--multiple <files>",
                       "Input files", CommandOptionType.MultipleValue);

            var result = app.Parse("-m", "input1.txt", "--multiple", "input2.txt");

            var builder = new ConfigurationBuilder()
                          .AddCommandLineOptions(map.FromCommand(result.SelectedCommand))
                          .Build();

            var options = new Simple();

            builder.Bind(options);

            options
            .Should()
            .BeEquivalentTo(new Simple
            {
                Multiple = new[] { "input1.txt", "input2.txt" }
            });
        }
예제 #5
0
        public void SingleOrNoValue(bool expected, params string[] args)
        {
            var map = new MapOptions <Simple>();

            var app = new CommandLineApplication();

            app.Option <bool>("-d|--debug", "enable debug", CommandOptionType.SingleOrNoValue)
            .Map(map, to => to.Debug);

            var result  = app.Parse(args);
            var builder = new ConfigurationBuilder()
                          .AddCommandLineOptions(map.FromCommand(result.SelectedCommand))
                          .Build();

            var options = new Simple();

            builder.Bind(options);

            options
            .Should()
            .BeEquivalentTo(new Simple
            {
                Debug = expected
            });
        }
예제 #6
0
        public void OptionArguments()
        {
            var map = new MapOptions <Simple>();

            var app = new CommandLineApplication();

            app.Option("-f|--files <files>", "Input files", CommandOptionType.MultipleValue)
            .Map(map, to => to.Multiple);

            var result = app.Parse("-f", "input1.txt", "--files", "input2.txt");

            var builder = new ConfigurationBuilder()
                          .AddJsonFile("test.json")
                          .AddCommandLineOptions(map.FromCommand(result.SelectedCommand))
                          .Build();

            var options = new Simple();

            builder.Bind(options);

            options
            .Should()
            .BeEquivalentTo(new Simple
            {
                Multiple = new[] { "input1.txt", "input2.txt" },
                Single   = "my-value"
            });
        }