Esempio n. 1
0
        public void ShortNameIsCaseSensitive()
        {
            CommandModel model = new CommandModel()
                                 .Option <string>("foo", "f", string.Empty, (cmd, v) => cmd.Get <Dictionary <string, string> >()["foo"] = v)
                                 .Option <string>("bar", "F", string.Empty, (cmd, v) => cmd.Get <Dictionary <string, string> >()["bar"] = v);

            Command cmd1 = model.Parse("-f", "123", "-F", "456");

            cmd1.Get <Dictionary <string, string> >()["foo"].ShouldBe("123");
            cmd1.Get <Dictionary <string, string> >()["bar"].ShouldBe("456");

            Command cmd2 = model.Parse("-f:123", "-F:456");

            cmd2.Get <Dictionary <string, string> >()["foo"].ShouldBe("123");
            cmd2.Get <Dictionary <string, string> >()["bar"].ShouldBe("456");

            Command cmd3 = model.Parse("/f", "123", "/F", "456");

            cmd3.Get <Dictionary <string, string> >()["foo"].ShouldBe("123");
            cmd3.Get <Dictionary <string, string> >()["bar"].ShouldBe("456");

            Command cmd4 = model.Parse("/f:123", "/F:456");

            cmd4.Get <Dictionary <string, string> >()["foo"].ShouldBe("123");
            cmd4.Get <Dictionary <string, string> >()["bar"].ShouldBe("456");
        }
        public void ShortNameWorksAsOption()
        {
            CommandModel model = new CommandModel()
                .Option<string>("foo", "f", string.Empty, (cmd, v) => cmd.Get<Dictionary<string, string>>()["foo"] = v)
                .Option<string>("bar", "b", string.Empty, (cmd, v) => cmd.Get<Dictionary<string, string>>()["bar"] = v);

            Command cmd1 = model.Parse("-f", "123", "-b:456");
            cmd1.Get<Dictionary<string, string>>()["foo"].ShouldBe("123");
            cmd1.Get<Dictionary<string, string>>()["bar"].ShouldBe("456");

            Command cmd2 = model.Parse("/f", "123", "/b:456");
            cmd2.Get<Dictionary<string, string>>()["foo"].ShouldBe("123");
            cmd2.Get<Dictionary<string, string>>()["bar"].ShouldBe("456");
        }
Esempio n. 3
0
        public void CommandModelWillParseStrings()
        {
            var model = new CommandModel()
                .Option<string>("foo", (cmd, v) => cmd.Get<Dictionary<string, string>>()["foo"] = v)
                .Option<string>("bar", (cmd, v) => cmd.Get<Dictionary<string, string>>()["bar"] = v);

            var cmd1 = model.Parse("/foo", "123", "/bar:456");
            cmd1.Get<Dictionary<string, string>>()["foo"].ShouldBe("123");
            cmd1.Get<Dictionary<string, string>>()["bar"].ShouldBe("456");

            var cmd2 = model.Parse("--foo", "123", "--bar:456");
            cmd2.Get<Dictionary<string, string>>()["foo"].ShouldBe("123");
            cmd2.Get<Dictionary<string, string>>()["bar"].ShouldBe("456");
        }
Esempio n. 4
0
        public void CommandModelWillParseIntegers()
        {
            var model = new CommandModel()
                .Option<int>("foo", (cmd, v) => cmd.Get<Dictionary<string, int>>()["foo"] = v)
                .Option<int>("bar", (cmd, v) => cmd.Get<Dictionary<string, int>>()["bar"] = v);

            var cmd1 = model.Parse(new[] { "/foo", "123", "/bar:456" });
            cmd1.Get<Dictionary<string, int>>()["foo"].ShouldBe(123);
            cmd1.Get<Dictionary<string, int>>()["bar"].ShouldBe(456);

            var cmd2 = model.Parse(new[] { "--foo", "123", "--bar:456" });
            cmd2.Get<Dictionary<string, int>>()["foo"].ShouldBe(123);
            cmd2.Get<Dictionary<string, int>>()["bar"].ShouldBe(456);
        }
Esempio n. 5
0
        public void ShortNameWorksAsOption()
        {
            CommandModel model = new CommandModel()
                                 .Option <string>("foo", "f", string.Empty, (cmd, v) => cmd.Get <Dictionary <string, string> >()["foo"] = v)
                                 .Option <string>("bar", "b", string.Empty, (cmd, v) => cmd.Get <Dictionary <string, string> >()["bar"] = v);

            Command cmd1 = model.Parse("-f", "123", "-b:456");

            cmd1.Get <Dictionary <string, string> >()["foo"].ShouldBe("123");
            cmd1.Get <Dictionary <string, string> >()["bar"].ShouldBe("456");

            Command cmd2 = model.Parse("/f", "123", "/b:456");

            cmd2.Get <Dictionary <string, string> >()["foo"].ShouldBe("123");
            cmd2.Get <Dictionary <string, string> >()["bar"].ShouldBe("456");
        }
Esempio n. 6
0
        public void CommandModelWillParseStrings()
        {
            var model = new CommandModel()
                        .Option <string>("foo", (cmd, v) => cmd.Get <Dictionary <string, string> >()["foo"] = v)
                        .Option <string>("bar", (cmd, v) => cmd.Get <Dictionary <string, string> >()["bar"] = v);

            var cmd1 = model.Parse("/foo", "123", "/bar:456");

            cmd1.Get <Dictionary <string, string> >()["foo"].ShouldBe("123");
            cmd1.Get <Dictionary <string, string> >()["bar"].ShouldBe("456");

            var cmd2 = model.Parse("--foo", "123", "--bar:456");

            cmd2.Get <Dictionary <string, string> >()["foo"].ShouldBe("123");
            cmd2.Get <Dictionary <string, string> >()["bar"].ShouldBe("456");
        }
Esempio n. 7
0
        public void CommandModelWillParseIntegers()
        {
            var model = new CommandModel()
                        .Option <int>("foo", (cmd, v) => cmd.Get <Dictionary <string, int> >()["foo"] = v)
                        .Option <int>("bar", (cmd, v) => cmd.Get <Dictionary <string, int> >()["bar"] = v);

            var cmd1 = model.Parse(new[] { "/foo", "123", "/bar:456" });

            cmd1.Get <Dictionary <string, int> >()["foo"].ShouldBe(123);
            cmd1.Get <Dictionary <string, int> >()["bar"].ShouldBe(456);

            var cmd2 = model.Parse(new[] { "--foo", "123", "--bar:456" });

            cmd2.Get <Dictionary <string, int> >()["foo"].ShouldBe(123);
            cmd2.Get <Dictionary <string, int> >()["bar"].ShouldBe(456);
        }
        public void LongNameIsCaseInsensitive()
        {
            CommandModel model = new CommandModel()
                .Option<string>("foo", "f", string.Empty, (cmd, v) => cmd.Get<Dictionary<string, string>>()["foo"] = v)
                .Option<string>("bar", "b", string.Empty, (cmd, v) => cmd.Get<Dictionary<string, string>>()["bar"] = v);

            Command cmd1 = model.Parse("--FoO", "123", "--BaR:456");
            cmd1.Get<Dictionary<string, string>>()["foo"].ShouldBe("123");
            cmd1.Get<Dictionary<string, string>>()["bar"].ShouldBe("456");
        }
Esempio n. 9
0
        public void ProgramHelpIsRecognized()
        {
            CommandModel model = Program.CreateCommandModel();

            model.Parse("-?").Model.Name.ShouldBe("{show help}");
            model.Parse("/?").Model.Name.ShouldBe("{show help}");
            model.Parse("-h").Model.Name.ShouldBe("{show help}");
            model.Parse("/h").Model.Name.ShouldBe("{show help}");
            model.Parse("-H").Model.Name.ShouldBe("{show help}");
            model.Parse("/H").Model.Name.ShouldBe("{show help}");
            model.Parse("--help").Model.Name.ShouldBe("{show help}");
            model.Parse("--HeLp").Model.Name.ShouldBe("{show help}");
        }
Esempio n. 10
0
        public void LongNameIsCaseInsensitive()
        {
            CommandModel model = new CommandModel()
                                 .Option <string>("foo", "f", string.Empty, (cmd, v) => cmd.Get <Dictionary <string, string> >()["foo"] = v)
                                 .Option <string>("bar", "b", string.Empty, (cmd, v) => cmd.Get <Dictionary <string, string> >()["bar"] = v);

            Command cmd1 = model.Parse("--FoO", "123", "--BaR:456");

            cmd1.Get <Dictionary <string, string> >()["foo"].ShouldBe("123");
            cmd1.Get <Dictionary <string, string> >()["bar"].ShouldBe("456");
        }
Esempio n. 11
0
        public static int Run(string[] args)
        {
            CommandModel model   = CreateCommandModel();
            Command      command = model.Parse(args);

            if (command.Run())
            {
                return(command.Get <int>());
            }
            Console.WriteLine("Unrecognized command");
            return(1);
        }
        public void ShortNameIsCaseSensitive()
        {
            CommandModel model = new CommandModel()
                .Option<string>("foo", "f", string.Empty, (cmd, v) => cmd.Get<Dictionary<string, string>>()["foo"] = v)
                .Option<string>("bar", "F", string.Empty, (cmd, v) => cmd.Get<Dictionary<string, string>>()["bar"] = v);

            Command cmd1 = model.Parse("-f", "123", "-F", "456");
            cmd1.Get<Dictionary<string, string>>()["foo"].ShouldBe("123");
            cmd1.Get<Dictionary<string, string>>()["bar"].ShouldBe("456");

            Command cmd2 = model.Parse("-f:123", "-F:456");
            cmd2.Get<Dictionary<string, string>>()["foo"].ShouldBe("123");
            cmd2.Get<Dictionary<string, string>>()["bar"].ShouldBe("456");

            Command cmd3 = model.Parse("/f", "123", "/F", "456");
            cmd3.Get<Dictionary<string, string>>()["foo"].ShouldBe("123");
            cmd3.Get<Dictionary<string, string>>()["bar"].ShouldBe("456");

            Command cmd4 = model.Parse("/f:123", "/F:456");
            cmd4.Get<Dictionary<string, string>>()["foo"].ShouldBe("123");
            cmd4.Get<Dictionary<string, string>>()["bar"].ShouldBe("456");
        }
Esempio n. 13
0
        public void ProgamOptionsAreParsed()
        {
            CommandModel model = Program.CreateCommandModel();

            model.Parse("-u", "hello").Get <StartOptions>().Urls.ShouldBe(new[] { "hello" });
            model.Parse("-u:hello").Get <StartOptions>().Urls.ShouldBe(new[] { "hello" });
            model.Parse("/u", "hello").Get <StartOptions>().Urls.ShouldBe(new[] { "hello" });
            model.Parse("/u:hello").Get <StartOptions>().Urls.ShouldBe(new[] { "hello" });
            model.Parse("--url:hello").Get <StartOptions>().Urls.ShouldBe(new[] { "hello" });
            model.Parse("--url", "hello").Get <StartOptions>().Urls.ShouldBe(new[] { "hello" });

            model.Parse("-u", "1", "-u", "2").Get <StartOptions>().Urls.ShouldBe(new[] { "1", "2" });

            model.Parse("--port", "8080").Get <StartOptions>().Port.ShouldBe(8080);
            model.Parse("--server", "alpha").Get <StartOptions>().ServerFactory.ShouldBe("alpha");

            model.Parse("MyProgram.Startup").Get <StartOptions>().AppStartup.ShouldBe("MyProgram.Startup");

            var options = model.Parse(
                "-s:Microsoft.Owin.Host.HttpListener",
                "-u:http://localhost:5000/path/",
                "-p:5000",
                "-o:\"c:\\my file.log\"",
                "--settings:Microsoft.Owin.Hosting.settings",
                // "-v:value?",
                "-b:Microsoft.Owin.Boot.AspNet",
                "My.Application, MyAssembly").Get <StartOptions>();

            options.ServerFactory.ShouldBe("Microsoft.Owin.Host.HttpListener");
            options.Urls.ShouldBe(new[] { "http://localhost:5000/path/" });
            options.Port.ShouldBe(5000);
            options.Settings.ShouldBe(new Dictionary <string, string>
            {
                { "boot", "Microsoft.Owin.Boot.AspNet" },
                { "alpha", "42" },
                { "traceoutput", "\"c:\\my file.log\"" },
                // { "traceverbosity", "value?" },
            });
            options.AppStartup.ShouldBe("My.Application, MyAssembly");
        }