Пример #1
0
        public void RequiredParamsAreBeforeOptional()
        {
            using var sw = new StringWriter();
            Console.SetOut(sw);

            var args   = new[] { "--a", "b", "--b", "b" };
            var parser = new CommandlineParser(args, new CommandlineArgumentRules
            {
                new OptionalCommandlineArgumentRule("a", "Default A", "Optional"),
                new RequiredCommandlineArgumentRule("b", "Required")
            });

            var output = new ConsoleOutputFormatter(parser);
            var l      = $"Usage: {AppName}";

            output.Write();
            var expected =
                $"{l}\r\n" +
                (new string(' ', l.Length + 2)) + "--b\r\n" +
                (new string(' ', l.Length + 2)) + "[--a=<Default A>]\r\n" +
                "\r\n" +
                "a  :Optional\r\n" +
                "b  :Required\r\n";

            Assert.AreEqual(expected, sw.ToString());
        }
Пример #2
0
        public void OptionalRuleDefaultValuesAreNotGiven()
        {
            using var sw = new StringWriter();
            Console.SetOut(sw);

            var args   = new[] { "--a", "b", "--b", "b" };
            var parser = new CommandlineParser(args, new CommandlineArgumentRules
            {
                new OptionalCommandlineArgumentRule("a", "Default A", "Optional A"),
                new OptionalCommandlineArgumentRule("b", null, "Optional B")
            });

            var output = new ConsoleOutputFormatter(parser);
            var l      = $"Usage: {AppName}";

            output.Write();
            var expected =
                $"{l}\r\n" +
                (new string(' ', l.Length + 2)) + "[--a=<Default A>]\r\n" +
                (new string(' ', l.Length + 2)) + "[--b]\r\n" +
                "\r\n" +
                "a  :Optional A\r\n" +
                "b  :Optional B\r\n";

            Assert.AreEqual(expected, sw.ToString());
        }
Пример #3
0
        private static void Main(string[] args)
        {
            var arguments = new CommandlineParser(args, new CommandlineArgumentRules
            {
                new HelpCommandlineArgumentRule(new [] { "help", "h" }),
                new OptionalCommandlineArgumentRule(new [] { "iterations", "i" }, "5", "The number of test itarations we wish to run.\n\rThis is the number of time we want to randomly stop/start watching a folder."),
                new OptionalCommandlineArgumentRule(new [] { "folders", "f" }, "5", "The number of folders watched at once."),
                new OptionalCommandlineArgumentRule(new [] { "change", "c" }, "10", "How often we want to change to another folder (in seconds)."),
                new OptionalCommandlineArgumentRule(new [] { "unique", "u" }, "true", "If we want to use a unique watcher, shared, or use a watcher per directory."),
                new OptionalCommandlineArgumentRule(new [] { "stats", "s" }, "true", "Display stats every 10 seconds."),
                new OptionalCommandlineArgumentRule(new [] { "quiet", "q" }, "false", "Do not display the folder updates."),
                new OptionalCommandlineArgumentRule(new [] { "drives", "d" }, "false", "Test all the drives only."),
                new OptionalCommandlineArgumentRule(new [] { "random", "r" }, "false", "Randomly create various folders/files and check for update."),
            });

            // check for help
            if (arguments.IsHelp())
            {
                var help = new ConsoleOutputFormatter(arguments);
                help.Write(  );
                return;
            }

            var   options = new Options(arguments);
            ILoad load;

            if (options.Drives)
            {
                load = new Drives(options);
            }
            else if (options.Random)
            {
                load = new Random(options);
            }
            else
            {
                load = new Load(options);
            }

            load?.Start();

            WaitForCtrlC();

            load?.Stop();
            load?.Dispose();
        }
Пример #4
0
        public void MultipleRequired()
        {
            using var sw = new StringWriter();
            Console.SetOut(sw);

            var args   = new[] { "--a", "b" };
            var parser = new CommandlineParser(args, new CommandlineArgumentRules
            {
                new RequiredCommandlineArgumentRule(new [] { "a", "b" }, "Required AB")
            });

            var output = new ConsoleOutputFormatter(parser);
            var l      = $"Usage: {AppName}";

            output.Write();
            var expected =
                $"{l}\r\n" +
                (new string(' ', l.Length + 2)) + "--a, --b\r\n" +
                "\r\n" +
                "a, b  :Required AB\r\n";

            Assert.AreEqual(expected, sw.ToString());
        }
Пример #5
0
        public void SingleHelp()
        {
            using var sw = new StringWriter();
            Console.SetOut(sw);

            var args   = new[] { "--a", "b" };
            var parser = new CommandlineParser(args, new CommandlineArgumentRules
            {
                new HelpCommandlineArgumentRule("a", "This is help")
            });

            var output = new ConsoleOutputFormatter(parser);
            var l      = $"Usage: {AppName}";

            output.Write();
            var expected =
                $"{l}\r\n" +
                (new string(' ', l.Length + 2)) + "[--a]\r\n" +
                "\r\n" +
                "a  :This is help\r\n";

            Assert.AreEqual(expected, sw.ToString());
        }