예제 #1
0
        public void PropertiesOption()
        {
            if (style == ParserStyle.Basic)
            {
                return;
            }

            String[] args = new String[] { "-Jsource=1.5", "-J", "target", "1.5", "foo" };

            Options options = new Options();

            options.AddOption(OptionBuilder.New().WithValueSeparator().HasArguments(2).Create('J'));

            ICommandLine cl = parser.Parse(options, args);

            IList values = cl.GetOptionValues("J");

            Assert.IsNotNull(values, "null values");
            Assert.AreEqual(4, values.Count, "number of values");
            Assert.AreEqual("source", values[0], "value 1");
            Assert.AreEqual("1.5", values[1], "value 2");
            Assert.AreEqual("target", values[2], "value 3");
            Assert.AreEqual("1.5", values[3], "value 4");
            IEnumerable <string> argsleft = cl.Arguments;

            Assert.AreEqual(1, argsleft.Count(), "Should be 1 arg left");
            Assert.AreEqual("foo", argsleft.First(), "Expecting foo");
        }
예제 #2
0
        public void Ant()
        {
            Options options = new Options();

            options.AddOption("help", false, "print this message");
            options.AddOption("projecthelp", false, "print project help information");
            options.AddOption("version", false, "print the version information and exit");
            options.AddOption("quiet", false, "be extra quiet");
            options.AddOption("verbose", false, "be extra verbose");
            options.AddOption("debug", false, "print debug information");
            options.AddOption("logfile", true, "use given file for log");
            options.AddOption("logger", true, "the class which is to perform the logging");
            options.AddOption("listener", true, "add an instance of a class as a project listener");
            options.AddOption("buildfile", true, "use given buildfile");
            options.AddOption(OptionBuilder.New().WithDescription("use value for given property")
                              .HasArguments()
                              .WithValueSeparator()
                              .Create('D'));
            //, null, true, , false, true );
            options.AddOption("find", true, "search for buildfile towards the root of the filesystem and use it");

            String[] args = new String[] { "-buildfile", "mybuild.xml",
                                           "-Dproperty=value", "-Dproperty1=value1",
                                           "-projecthelp" };

            // use the GNU parser
            ICommandLineParser parser = new GnuParser();

            ICommandLine line = parser.Parse(options, args);

            // check multiple values
            String[] opts = line.GetOptionValues("D");
            Assert.AreEqual("property", opts[0]);
            Assert.AreEqual("value", opts[1]);
            Assert.AreEqual("property1", opts[2]);
            Assert.AreEqual("value1", opts[3]);

            // check single value
            Assert.AreEqual("mybuild.xml", line.GetOptionValue("buildfile").Value);

            // check option
            Assert.IsTrue(line.HasOption("projecthelp"));
        }
예제 #3
0
 public static string[] GetOptionValues(this ICommandLine commandLine, char optionName)
 {
     return(commandLine.GetOptionValues(optionName.ToString(CultureInfo.InvariantCulture)));
 }