コード例 #1
0
        public void delegateFact()
        {
            int portNumber = -1;
            CommandLineIntOption portOption = new CommandLineIntOption("port", "p");
            portOption.Delegate = arg => portNumber = arg.Value;
            parser.AddOption(portOption);

            parser.Parse(new string[] {"-p8080"});
            Assert.Equal(8080, portNumber);
        }
コード例 #2
0
        public void floatParameterThrowsException()
        {
            CommandLineIntOption port = new CommandLineIntOption("port", "p");
            parser.AddOption(port);

            Assert.Throws<ParsingException>(
                delegate
                {
                    parser.Parse(new string[] { "--port", "4.0" });
                });
        }
コード例 #3
0
        public void lesserThanMinValueThrowsException()
        {
            CommandLineIntOption port = new CommandLineIntOption("port", "p");
            port.MaxValue = 1;
            port.MinValue = -1;
            parser.AddOption(port);

            Assert.Throws<ParsingException>(
                delegate
                {
                    parser.Parse(new string[] { "--port", "-37" });
                });
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: miryn/DPP
        static void Example3(string[] args)
        {
            CommandLineParser parser = new CommandLineParser();
            int intValue = 0;

            CommandLineIntOption intOption = new CommandLineIntOption("number");
            intOption.MinValue = 100;
            intOption.MaxValue = 200;
            intOption.ParameterType = ParameterType.Optional;
            intOption.Delegate = x => intValue = x.Value;
            parser.AddOption(intOption);

            parser.Parse(args);

            Console.WriteLine("Value: " + intValue);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: miryn/DPP
        static void Main(string[] args)
        {
            TestGnuTime();

            TestValueType();

            TestRequiredAndOptionalParameters();

            TestExceptions();

            TestOptionalParameters();

            TestTerminator();

            TestParsingException();

            TestConfigExceptions();

            TestRequiredOption();

            //args = new string[] { "--listen",  "--port", "80", "--hello=world" };
            args = new string[] { "-p", "80", "-l", "naky", "navic" };
            //args = new string[] { "-lp80" };
            //args = new string[] { "--port=100000" };
            //args = new string[] { "--hello=world" };

            CommandLineParser parser = new CommandLineParser();

            CommandLineIntOption p = new CommandLineIntOption("port", "p");
            p.MaxValue = 65535;
            p.Delegate = x => Console.WriteLine("Já jsem delegát: " + x.Value);
            parser.AddOption(p);

            CommandLineBoolOption l = new CommandLineBoolOption(name: "listen", shortName: "l");
            parser.AddOption(l);

            CommandLineStringOption s = new CommandLineStringOption("hello");
            s.AllowedValues.AddRange(new string[] { "abc", "def", "ghi" });
            parser.AddOption(s);

            List<string> extraParameters;

            //try
            {
                // run the parser
                extraParameters = parser.Parse(args);
            }

            /*catch (ParsingException e)
            {
                Console.WriteLine(e.Message);
                return;
            }*/
            /*catch (OptionNotFoundException e)
            {
                Console.WriteLine(e.Message);
                return;
            }*/

            Console.WriteLine("p.Value: " + p.Value);
            Console.WriteLine("l.Present: " + l.Present);
            Console.WriteLine("s.Value: " + s.Value);
            Console.WriteLine("extraParameters: " + string.Join(",", extraParameters));
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: miryn/DPP
        static void TestValueType()
        {
            CommandLineParser parser = new CommandLineParser();

            CommandLineIntOption intOption = new CommandLineIntOption("int", "i");
            parser.AddOption(intOption);

            var otherParams = parser.Parse(new string[] { "-i", "10" });

            TestAssert(intOption.Value == 10);
            TestAssert(intOption.Value.GetType() == typeof(int));
        }
コード例 #7
0
        public void maxValueBorderFact()
        {
            CommandLineIntOption port = new CommandLineIntOption("port", "p");
            port.MaxValue = -1;
            parser.AddOption(port);

            parser.Parse(new string[] { "--port", "-1" });
            Assert.Equal(-1, port.Value);
        }
コード例 #8
0
        public void tooSmallParameterThrowsException()
        {
            CommandLineIntOption port = new CommandLineIntOption("port", "p");
            parser.AddOption(port);

            Assert.Throws<ParsingException>(
                delegate
                {
                    parser.Parse(new string[] { "--port", Int64.MinValue.ToString() });
                });
        }
コード例 #9
0
        public void parameterTypeNoneFact()
        {
            CommandLineIntOption port = new CommandLineIntOption("port");
            port.ParameterType = ParameterType.None;
            parser.AddOption(port);

            parser.Parse(new string[] { "--port", "8080" });

            Assert.Null(port.Value);
        }
コード例 #10
0
        public void parameterTypeOptionalFact()
        {
            CommandLineIntOption port = new CommandLineIntOption("port");
            port.ParameterType = ParameterType.Optional;
            parser.AddOption(port);

            parser.Parse(new string[] { "--port", "8080" });

            Assert.Equal(8080, port.Value);
        }
コード例 #11
0
        public void nullParameterThrowsException()
        {
            CommandLineIntOption port = new CommandLineIntOption("port", "p");
            parser.AddOption(port);

            parser.Parse(new string[] { "--port", null });

            Assert.Equal(0, port.Value);
        }
コード例 #12
0
        public void missingParameterTypeOptionalFact()
        {
            CommandLineIntOption port = new CommandLineIntOption("port", "p");
            port.ParameterType = ParameterType.Optional;
            parser.AddOption(port);

            parser.Parse(new string[] { "-p" });

            Assert.Null(port.Value);
        }
コード例 #13
0
        public void minValueFact()
        {
            CommandLineIntOption port = new CommandLineIntOption("port", "p");
            port.MinValue = 1;
            port.ParameterType = ParameterType.Optional;
            parser.AddOption(port);

            parser.Parse(new string[] { "-p", Int32.MaxValue.ToString() });
            Assert.Equal(Int32.MaxValue, port.Value);
        }
コード例 #14
0
        public void minValueBorderFact()
        {
            CommandLineIntOption port = new CommandLineIntOption("port", "p");
            port.ParameterType = ParameterType.Optional;
            port.MinValue = 1;
            parser.AddOption(port);

            parser.Parse(new string[] { "-p1"});
            Assert.Equal(1, port.Value);
        }
コード例 #15
0
        public void minmaxValueFact()
        {
            CommandLineIntOption port = new CommandLineIntOption("port", "p");
            port.MaxValue = 1;
            port.MinValue = -1;
            parser.AddOption(port);

            parser.Parse(new string[] { "--port", "0" });
            Assert.Equal(0, port.Value);
        }