AddOption() публичный Метод

public AddOption ( Option option ) : Options
option Option
Результат Options
Пример #1
0
 protected override Options CreateOptions()
 {
     Options options = new Options();
     options.AddOption("file", false, "Indicates the application will store data into files.");
     options.AddOption("dir", true, "The application directory.");
     return options;
 }
Пример #2
0
        public void OptionWithoutShortFormat()
        {
            // related to Bugzilla #19383 (CLI-67)
            Options options = new Options();

            options.AddOption(new Option("a", "aaa", false, "aaaaaaa"));
            options.AddOption(new Option(null, "bbb", false, "bbbbbbb"));
            options.AddOption(new Option("c", null, false, "ccccccc"));

            HelpFormatter formatter = new HelpFormatter();
            StringWriter  output    = new StringWriter();

            var settings = new HelpSettings {
                Width              = 80,
                LeftPadding        = 2,
                DescriptionPadding = 2,
                CommandLineSyntax  = "foobar"
            };

            formatter.PrintHelp(options, settings, output, true);
            Assert.AreEqual(
                "usage: foobar [-a] [--bbb] [-c]" + Eol +
                "  -a,--aaa  aaaaaaa" + Eol +
                "     --bbb  bbbbbbb" + Eol +
                "  -c        ccccccc" + Eol
                , output.ToString());
        }
Пример #3
0
 private static Options GetOptions()
 {
     Options options = new Options();
     options.AddOption("c", "conf", true, "A file containing the configurations to make the " +
                       "instance of the network simulator.");
     options.AddOption("");
     return options;
 }
Пример #4
0
        public static Options Parse(String pattern)
        {
            char       opt      = ' ';
            bool       required = false;
            OptionType type     = OptionType.None;

            Options options = new Options();

            for (int i = 0; i < pattern.Length; i++)
            {
                char ch = pattern[i];

                // a value code comes after an option and specifies
                // details about it
                if (!IsValueCode(ch))
                {
                    if (opt != ' ')
                    {
                        OptionBuilder builder = new OptionBuilder();
                        builder.HasArgument(type != OptionType.None);
                        builder.IsRequired(required);
                        builder.WithType(type);

                        // we have a previous one to deal with
                        options.AddOption(builder.Create(opt));
                        required = false;
                        type     = OptionType.None;
                        opt      = ' ';
                    }

                    opt = ch;
                }
                else if (ch == '!')
                {
                    required = true;
                }
                else
                {
                    type = getValueClass(ch);
                }
            }

            if (opt != ' ')
            {
                OptionBuilder builder = new OptionBuilder();
                builder.HasArgument(type != OptionType.None);
                builder.IsRequired(required);
                builder.WithType(type);

                // we have a final one to deal with
                options.AddOption(builder.Create(opt));
            }

            return(options);
        }
Пример #5
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");
        }
Пример #6
0
        public static Options Parse(String pattern)
        {
            char opt = ' ';
            bool required = false;
            OptionType type = OptionType.None;

            Options options = new Options();

            for (int i = 0; i < pattern.Length; i++) {
                char ch = pattern[i];

                // a value code comes after an option and specifies
                // details about it
                if (!IsValueCode(ch)) {
                    if (opt != ' ') {
                        OptionBuilder builder = new OptionBuilder();
                        builder.HasArgument(type != OptionType.None);
                        builder.IsRequired(required);
                        builder.WithType(type);

                        // we have a previous one to deal with
                        options.AddOption(builder.Create(opt));
                        required = false;
                        type = OptionType.None;
                        opt = ' ';
                    }

                    opt = ch;
                } else if (ch == '!') {
                    required = true;
                } else {
                    type = getValueClass(ch);
                }
            }

            if (opt != ' ') {
                OptionBuilder builder = new OptionBuilder();
                builder.HasArgument(type != OptionType.None);
                builder.IsRequired(required);
                builder.WithType(type);

                // we have a final one to deal with
                options.AddOption(builder.Create(opt));
            }

            return options;
        }
Пример #7
0
        public void Ls()
        {
            Options options = new Options();

            options.AddOption("a", "all", false, "do not hide entries starting with .");
            options.AddOption("A", "almost-all", false, "do not list implied . and ..");
            options.AddOption("b", "escape", false, "print octal escapes for nongraphic characters");
            options.AddOption(OptionBuilder.New().WithLongName("block-size")
                              .WithDescription("use SIZE-byte blocks")
                              .HasArgument()
                              .WithArgumentName("SIZE")
                              .Create());
            options.AddOption("B", "ignore-backups", false, "do not list implied entried ending with ~");
            options.AddOption("c", false, "with -lt: sort by, and show, ctime (time of last modification of file status information) with -l:show ctime and sort by name otherwise: sort by ctime");
            options.AddOption("C", false, "list entries by columns");

            String[] args = new String[] { "--block-size=10" };

            // create the command line parser
            ICommandLineParser parser = new PosixParser();

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

            Assert.IsTrue(line.HasOption("block-size"));
            Assert.AreEqual("10", line.GetOptionValue("block-size").Value);
        }
Пример #8
0
        public void PrintSortedUsageWithNullComparer()
        {
            Options opts = new Options();

            opts.AddOption(new Option("a", "first"));
            opts.AddOption(new Option("b", "second"));
            opts.AddOption(new Option("c", "third"));

            HelpFormatter helpFormatter = new HelpFormatter();

            StringWriter output = new StringWriter();

            helpFormatter.PrintUsage(opts, new HelpSettings {
                Width = 80, CommandLineSyntax = "app", OptionComparer = null
            }, output);

            Assert.AreEqual("usage: app [-a] [-b] [-c]" + Eol, output.ToString());
        }
Пример #9
0
 private static Options GetOptions()
 {
     Options options = new Options();
     options.AddOption("nodeconfig", true, "The node configuration file (default: node.conf).");
     options.AddOption("netconfig", true, "The network configuration file (default: network.conf).");
     options.AddOption("host", true, "The interface address to bind the socket on the local machine " +
                       "(optional - if not given binds to all interfaces)");
     options.AddOption("port", true, "The port to bind the socket.");
     options.AddOption("install", false, "Installs the node as a service in this machine");
     options.AddOption("user", true, "The user name for the authorization credentials to install/uninstall " +
                      "the service.");
     options.AddOption("password", true, "The password credential used to authorize installation and " +
                      "uninstallation of the service in this machine.");
     options.AddOption("service", false, "Starts the node as a service (used internally)");
     options.AddOption("uninstall", false, "Uninstalls a service for the node that was previously installed.");
     options.AddOption("storage", true, "The type of storage used to persist node information and data");
     options.AddOption("protocol", true, "The connection protocol used by this node to listen connections");
     return options;
 }
Пример #10
0
        public void PrintUsage()
        {
            var optionA = new Option("a", "first");
            var optionB = new Option("b", "second");
            var optionC = new Option("c", "third");
            var opts    = new Options();

            opts.AddOption(optionA);
            opts.AddOption(optionB);
            opts.AddOption(optionC);
            var helpFormatter = new HelpFormatter();
            var bytesOut      = new MemoryStream();
            var printWriter   = new StreamWriter(bytesOut);

            helpFormatter.PrintUsage(opts, new HelpSettings {
                Width = 80, CommandLineSyntax = "app"
            }, printWriter);
            printWriter.Close();
            Assert.AreEqual("usage: app [-a] [-b] [-c]" + Eol, Encoding.UTF8.GetString(bytesOut.ToArray()));
        }
Пример #11
0
        public static Options CreateFromType(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            //if (!Attribute.IsDefined(type, typeof(OptionsAttribute)))
            //	throw new ArgumentException("The type '" + type + "' is not marked as options");

            MemberInfo[] members = type.FindMembers(MemberTypes.Field | MemberTypes.Property,
                                                    BindingFlags.Public | BindingFlags.Instance,
                                                    FilterMember, null);

            var groups         = new Dictionary <string, OptionGroup>();
            var requiredGroups = new List <string>();

            Attribute[] groupsAttrs = Attribute.GetCustomAttributes(type, typeof(OptionGroupAttribute));
            foreach (OptionGroupAttribute groupAttr in groupsAttrs)
            {
                OptionGroup group;
                if (!groups.TryGetValue(groupAttr.Name, out @group))
                {
                    @group = new OptionGroup {
                        IsRequired = groupAttr.IsRequired
                    };
                    groups[groupAttr.Name] = @group;
                    if (groupAttr.IsRequired)
                    {
                        requiredGroups.Add(groupAttr.Name);
                    }
                }
            }

            var options = new Options();

            foreach (MemberInfo member in members)
            {
                Option option = CreateOptionFromMember(member, groups);
                if (option != null)
                {
                    options.AddOption(option);
                }
            }

            foreach (var entry in groups)
            {
                var group = entry.Value;
                options.AddOptionGroup(group);
            }

            return(options);
        }
Пример #12
0
        public void GetOptionProperties()
        {
            string[] args = new String[] { "-Dparam1=value1", "-Dparam2=value2", "-Dparam3", "-Dparam4=value4", "-D", "--property", "foo=bar" };

            Options options = new Options();
            options.AddOption(OptionBuilder.New().WithValueSeparator().HasOptionalArgs(2).Create('D'));
            options.AddOption(OptionBuilder.New().WithValueSeparator().HasArguments(2).WithLongName("property").Create());

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

            IDictionary<string, string> props = cl.GetOptionProperties("D");

            Assert.IsNotNull(props, "null properties");
            Assert.AreEqual(4, props.Count, "number of properties in " + props);
            Assert.AreEqual("value1", props["param1"], "property 1");
            Assert.AreEqual("value2", props["param2"], "property 2");
            Assert.AreEqual("true", props["param3"], "property 3");
            Assert.AreEqual("value4", props["param4"], "property 4");

            Assert.AreEqual("bar", cl.GetOptionProperties("property")["foo"], "property with long format");
        }
Пример #13
0
        public void LongWithEqualSingleDash()
        {
            if (style == ParserStyle.Basic)
                return;

            String[] args = new String[] { "-foo=bar" };

            Options options = new Options();
            options.AddOption(OptionBuilder.New().WithLongName("foo").HasArgument().Create('f'));

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

            Assert.AreEqual("bar", cl.GetOptionValue("foo").Value);
        }
Пример #14
0
        public void GetOptionProperties()
        {
            string[] args = new String[] { "-Dparam1=value1", "-Dparam2=value2", "-Dparam3", "-Dparam4=value4", "-D", "--property", "foo=bar" };

            Options options = new Options();

            options.AddOption(OptionBuilder.New().WithValueSeparator().HasOptionalArgs(2).Create('D'));
            options.AddOption(OptionBuilder.New().WithValueSeparator().HasArguments(2).WithLongName("property").Create());

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

            IDictionary <string, string> props = cl.GetOptionProperties("D");

            Assert.IsNotNull(props, "null properties");
            Assert.AreEqual(4, props.Count, "number of properties in " + props);
            Assert.AreEqual("value1", props["param1"], "property 1");
            Assert.AreEqual("value2", props["param2"], "property 2");
            Assert.AreEqual("true", props["param3"], "property 3");
            Assert.AreEqual("value4", props["param4"], "property 4");

            Assert.AreEqual("bar", cl.GetOptionProperties("property")["foo"], "property with long format");
        }
Пример #15
0
        public void LongWithEqualSingleDash()
        {
            if (style == ParserStyle.Basic)
            {
                return;
            }

            String[] args = new String[] { "-foo=bar" };

            Options options = new Options();

            options.AddOption(OptionBuilder.New().WithLongName("foo").HasArgument().Create('f'));

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

            Assert.AreEqual("bar", cl.GetOptionValue("foo").Value);
        }
Пример #16
0
        public static Options CreateFromType(Type type)
        {
            if (type == null)
                throw new ArgumentNullException("type");

            //if (!Attribute.IsDefined(type, typeof(OptionsAttribute)))
            //	throw new ArgumentException("The type '" + type + "' is not marked as options");

            MemberInfo[] members = type.FindMembers(MemberTypes.Field | MemberTypes.Property,
                                                    BindingFlags.Public | BindingFlags.Instance,
                                                    FilterMember, null);

            var groups = new Dictionary<string, OptionGroup>();
            var requiredGroups = new List<string>();

            Attribute[] groupsAttrs = Attribute.GetCustomAttributes(type, typeof(OptionGroupAttribute));
            foreach (OptionGroupAttribute groupAttr in groupsAttrs) {
                OptionGroup group;
                if (!groups.TryGetValue(groupAttr.Name, out @group)) {
                    @group = new OptionGroup {IsRequired = groupAttr.IsRequired};
                    groups[groupAttr.Name] = @group;
                    if (groupAttr.IsRequired)
                        requiredGroups.Add(groupAttr.Name);
                }
            }

            var options = new Options();

            foreach (MemberInfo member in members) {
                Option option = CreateOptionFromMember(member, groups);
                if (option != null)
                    options.AddOption(option);
            }

            foreach(var entry in groups) {
                var group = entry.Value;
                options.AddOptionGroup(group);
            }

            return options;
        }
Пример #17
0
        public void PrintOptionWithEmptyArgNameUsage()
        {
            Option option = new Option("f", true, null);

            option.ArgumentName = "";
            option.IsRequired   = true;

            Options options = new Options();

            options.AddOption(option);

            StringWriter output = new StringWriter();

            HelpFormatter formatter = new HelpFormatter();

            formatter.PrintUsage(options, new HelpSettings {
                ArgumentName = null, CommandLineSyntax = "app", Width = 80
            }, output);

            Assert.AreEqual("usage: app -f" + Eol, output.ToString());
        }
Пример #18
0
        public void Groovy()
        {
            Options options = new Options();

            options.AddOption(
                OptionBuilder.New().WithLongName("define").
                WithDescription("define a system property").
                HasArgument(true).
                WithArgumentName("name=value").
                Create('D'));
            options.AddOption(
                OptionBuilder.New().HasArgument(false)
                .WithDescription("usage information")
                .WithLongName("help")
                .Create('h'));
            options.AddOption(
                OptionBuilder.New().HasArgument(false)
                .WithDescription("debug mode will print out full stack traces")
                .WithLongName("debug")
                .Create('d'));
            options.AddOption(
                OptionBuilder.New().HasArgument(false)
                .WithDescription("display the Groovy and JVM versions")
                .WithLongName("version")
                .Create('v'));
            options.AddOption(
                OptionBuilder.New().WithArgumentName("charset")
                .HasArgument()
                .WithDescription("specify the encoding of the files")
                .WithLongName("encoding")
                .Create('c'));
            options.AddOption(
                OptionBuilder.New().WithArgumentName("script")
                .HasArgument()
                .WithDescription("specify a command line script")
                .Create('e'));
            options.AddOption(
                OptionBuilder.New().WithArgumentName("extension")
                .HasOptionalArg()
                .WithDescription("modify files in place; create backup if extension is given (e.g. \'.bak\')")
                .Create('i'));
            options.AddOption(
                OptionBuilder.New().HasArgument(false)
                .WithDescription("process files line by line using implicit 'line' variable")
                .Create('n'));
            options.AddOption(
                OptionBuilder.New().HasArgument(false)
                .WithDescription("process files line by line and print result (see also -n)")
                .Create('p'));
            options.AddOption(
                OptionBuilder.New().WithArgumentName("port")
                .HasOptionalArg()
                .WithDescription("listen on a port and process inbound lines")
                .Create('l'));
            options.AddOption(
                OptionBuilder.New().WithArgumentName("splitPattern")
                .HasOptionalArg()
                .WithDescription("split lines using splitPattern (default '\\s') using implicit 'split' variable")
                .WithLongName("autosplit")
                .Create('a'));

            Parser       parser = new PosixParser();
            ICommandLine line   = parser.Parse(options, new String[] { "-e", "println 'hello'" }, true);

            Assert.IsTrue(line.HasOption('e'));
            Assert.AreEqual("println 'hello'", line.GetOptionValue('e').Value);
        }
Пример #19
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"));
        }
Пример #20
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"));
        }
Пример #21
0
        public void Ls()
        {
            Options options = new Options();
            options.AddOption("a", "all", false, "do not hide entries starting with .");
            options.AddOption("A", "almost-all", false, "do not list implied . and ..");
            options.AddOption("b", "escape", false, "print octal escapes for nongraphic characters");
            options.AddOption(OptionBuilder.New().WithLongName("block-size")
                                            .WithDescription("use SIZE-byte blocks")
                                            .HasArgument()
                                            .WithArgumentName("SIZE")
                                            .Create());
            options.AddOption("B", "ignore-backups", false, "do not list implied entried ending with ~");
            options.AddOption("c", false, "with -lt: sort by, and show, ctime (time of last modification of file status information) with -l:show ctime and sort by name otherwise: sort by ctime");
            options.AddOption("C", false, "list entries by columns");

            String[] args = new String[] { "--block-size=10" };

            // create the command line parser
            ICommandLineParser parser = new PosixParser();

            ICommandLine line = parser.Parse(options, args);
            Assert.IsTrue(line.HasOption("block-size"));
            Assert.AreEqual("10", line.GetOptionValue("block-size").Value);
        }
Пример #22
0
        public void Groovy()
        {
            Options options = new Options();

            options.AddOption(
                OptionBuilder.New().WithLongName("define").
                    WithDescription("define a system property").
                    HasArgument(true).
                    WithArgumentName("name=value").
                    Create('D'));
            options.AddOption(
                OptionBuilder.New().HasArgument(false)
                .WithDescription("usage information")
                .WithLongName("help")
                .Create('h'));
            options.AddOption(
                OptionBuilder.New().HasArgument(false)
                .WithDescription("debug mode will print out full stack traces")
                .WithLongName("debug")
                .Create('d'));
            options.AddOption(
                OptionBuilder.New().HasArgument(false)
                .WithDescription("display the Groovy and JVM versions")
                .WithLongName("version")
                .Create('v'));
            options.AddOption(
                OptionBuilder.New().WithArgumentName("charset")
                .HasArgument()
                .WithDescription("specify the encoding of the files")
                .WithLongName("encoding")
                .Create('c'));
            options.AddOption(
                OptionBuilder.New().WithArgumentName("script")
                .HasArgument()
                .WithDescription("specify a command line script")
                .Create('e'));
            options.AddOption(
                OptionBuilder.New().WithArgumentName("extension")
                .HasOptionalArg()
                .WithDescription("modify files in place; create backup if extension is given (e.g. \'.bak\')")
                .Create('i'));
            options.AddOption(
                OptionBuilder.New().HasArgument(false)
                .WithDescription("process files line by line using implicit 'line' variable")
                .Create('n'));
            options.AddOption(
                OptionBuilder.New().HasArgument(false)
                .WithDescription("process files line by line and print result (see also -n)")
                .Create('p'));
            options.AddOption(
                OptionBuilder.New().WithArgumentName("port")
                .HasOptionalArg()
                .WithDescription("listen on a port and process inbound lines")
                .Create('l'));
            options.AddOption(
                OptionBuilder.New().WithArgumentName("splitPattern")
                .HasOptionalArg()
                .WithDescription("split lines using splitPattern (default '\\s') using implicit 'split' variable")
                .WithLongName("autosplit")
                .Create('a'));

            Parser parser = new PosixParser();
            ICommandLine line = parser.Parse(options, new String[] { "-e", "println 'hello'" }, true);

            Assert.IsTrue(line.HasOption('e'));
            Assert.AreEqual("println 'hello'", line.GetOptionValue('e').Value);
        }
Пример #23
0
        public void OptionWithoutShortFormat2()
        {
            // related to Bugzilla #27635 (CLI-26)
            Option help       = new Option("h", "help", false, "print this message");
            Option version    = new Option("v", "version", false, "print version information");
            Option newRun     = new Option("n", "new", false, "Create NLT cache entries only for new items");
            Option trackerRun = new Option("t", "tracker", false, "Create NLT cache entries only for tracker items");

            Option timeLimit = OptionBuilder.New().WithLongName("limit")
                               .HasArgument()
                               .WithValueSeparator()
                               .WithDescription("Set time limit for execution, in mintues")
                               .Create("l");

            Option age = OptionBuilder.New().WithLongName("age")
                         .HasArgument()
                         .WithValueSeparator()
                         .WithDescription("Age (in days) of cache item before being recomputed")
                         .Create("a");

            Option server = OptionBuilder.New().WithLongName("server")
                            .HasArgument()
                            .WithValueSeparator()
                            .WithDescription("The NLT server address")
                            .Create("s");

            Option numResults = OptionBuilder.New().WithLongName("results")
                                .HasArgument()
                                .WithValueSeparator()
                                .WithDescription("Number of results per item")
                                .Create("r");

            Option configFile = OptionBuilder.New().WithLongName("config")
                                .HasArgument()
                                .WithValueSeparator()
                                .WithDescription("Use the specified configuration file")
                                .Create();

            Options mOptions = new Options();

            mOptions.AddOption(help);
            mOptions.AddOption(version);
            mOptions.AddOption(newRun);
            mOptions.AddOption(trackerRun);
            mOptions.AddOption(timeLimit);
            mOptions.AddOption(age);
            mOptions.AddOption(server);
            mOptions.AddOption(numResults);
            mOptions.AddOption(configFile);

            HelpFormatter formatter = new HelpFormatter();

            String       EOL    = Environment.NewLine;
            StringWriter output = new StringWriter();

            var settings = new HelpSettings {
                ArgumentName       = "arg",
                Width              = 80,
                Header             = "header",
                Footer             = "footer",
                DescriptionPadding = 2,
                LeftPadding        = 2,
                CommandLineSyntax  = "commandline"
            };

            formatter.PrintHelp(mOptions, settings, output, true);
            Assert.AreEqual(
                "usage: commandline [-a <arg>] [--config <arg>] [-h] [-l <arg>] [-n] [-r <arg>]" + EOL +
                "       [-s <arg>] [-t] [-v]" + EOL +
                "header" + EOL +
                "  -a,--age <arg>      Age (in days) of cache item before being recomputed" + EOL +
                "     --config <arg>   Use the specified configuration file" + EOL +
                "  -h,--help           print this message" + EOL +
                "  -l,--limit <arg>    Set time limit for execution, in mintues" + EOL +
                "  -n,--new            Create NLT cache entries only for new items" + EOL +
                "  -r,--results <arg>  Number of results per item" + EOL +
                "  -s,--server <arg>   The NLT server address" + EOL +
                "  -t,--tracker        Create NLT cache entries only for tracker items" + EOL +
                "  -v,--version        print version information" + EOL +
                "footer" + EOL
                , output.ToString());
        }
Пример #24
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");
        }
Пример #25
0
 public override void RegisterOptions(Options options)
 {
     options.AddOption("f", "file", true, "The file");
     options.AddOption("d", "dir", true, "The directory.");
 }
Пример #26
0
 public override void RegisterOptions(Options options)
 {
     options.AddOption("h", "address", true, "The address to a node of the network (typically a manager).");
     options.AddOption("x", "protocol", true, "Specifies the connection protocol ('http' or 'tcp').");
     options.AddOption("f", "format", true, "Format used to serialize messages to/from the manager " +
                                       "service ('xml', 'json' or 'binary')");
     options.AddOption("p", "password", true, "The challenge password used in all connection handshaking " +
                                         "throughout the network.");
     options.AddOption("u", "user", true, "The name of the user to authenticate in a HTTP connection.");
 }