Ejemplo n.º 1
0
        public void PrintHelpWithEmptySyntax()
        {
            var formatter = new HelpFormatter();

            Assert.Throws <InvalidOperationException>(() => formatter.PrintHelp(new Options(), new HelpSettings(), Console.Out, false),
                                                      "null command line syntax should be rejected");
            Assert.Throws <InvalidOperationException>(
                () => formatter.PrintHelp(new Options(), new HelpSettings {
                CommandLineSyntax = String.Empty
            }, Console.Out, false),
                "empty command line syntax should be rejected");
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 3
0
        public void HeaderStartingWithLineSeparator()
        {
            // related to Bugzilla #21215
            Options       options   = new Options();
            HelpFormatter formatter = new HelpFormatter();
            String        header    = Eol + "Header";
            String        footer    = "Footer";
            StringWriter  output    = new StringWriter();

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

            formatter.PrintHelp(options, settings, output, true);
            Assert.AreEqual(
                "usage: foobar" + Eol +
                "" + Eol +
                "Header" + Eol +
                "" + Eol +
                "Footer" + Eol
                , output.ToString());
        }
Ejemplo n.º 4
0
        public void Man()
        {
            String cmdLine =
                "man [-c|-f|-k|-w|-tZT device] [-adlhu7V] [-Mpath] [-Ppager] [-Slist] " +
                "[-msystem] [-pstring] [-Llocale] [-eextension] [section] page ...";
            Options options = new Options().
                              AddOption("a", "all", false, "find all matching manual pages.").
                              AddOption("d", "debug", false, "emit debugging messages.").
                              AddOption("e", "extension", false, "limit search to extension type 'extension'.").
                              AddOption("f", "whatis", false, "equivalent to whatis.").
                              AddOption("k", "apropos", false, "equivalent to apropos.").
                              AddOption("w", "location", false, "print physical location of man page(s).").
                              AddOption("l", "local-file", false, "interpret 'page' argument(s) as local filename(s)").
                              AddOption("u", "update", false, "force a cache consistency check.").
                              //FIXME - should generate -r,--prompt string
                              AddOption("r", "prompt", true, "provide 'less' pager with prompt.").
                              AddOption("c", "catman", false, "used by catman to reformat out of date cat pages.").
                              AddOption("7", "ascii", false, "display ASCII translation or certain latin1 chars.").
                              AddOption("t", "troff", false, "use troff format pages.").
                              //FIXME - should generate -T,--troff-device device
                              AddOption("T", "troff-device", true, "use groff with selected device.").
                              AddOption("Z", "ditroff", false, "use groff with selected device.").
                              AddOption("D", "default", false, "reset all options to their default values.").
                              //FIXME - should generate -M,--manpath path
                              AddOption("M", "manpath", true, "set search path for manual pages to 'path'.").
                              //FIXME - should generate -P,--pager pager
                              AddOption("P", "pager", true, "use program 'pager' to display output.").
                              //FIXME - should generate -S,--sections list
                              AddOption("S", "sections", true, "use colon separated section list.").
                              //FIXME - should generate -m,--systems system
                              AddOption("m", "systems", true, "search for man pages from other unix system(s).").
                              //FIXME - should generate -L,--locale locale
                              AddOption("L", "locale", true, "define the locale for this particular man search.").
                              //FIXME - should generate -p,--preprocessor string
                              AddOption("p", "preprocessor", true, "string indicates which preprocessor to run.\n" +
                                        " e - [n]eqn  p - pic     t - tbl\n" +
                                        " g - grap    r - refer   v - vgrind").
                              AddOption("V", "version", false, "show version.").
                              AddOption("h", "help", false, "show this usage message.");

            HelpFormatter hf = new HelpFormatter();

            hf.PrintHelp(options, new HelpSettings {
                CommandLineSyntax = cmdLine
            }, Console.Out, false);
        }
Ejemplo n.º 5
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());
        }