예제 #1
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());
        }
예제 #2
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());
        }
예제 #3
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Please enter a valid file path.");
                Console.WriteLine("\nEnter any key to close the application.");
                Console.ReadKey();
                return;
            }

            IInputFormatter inputter = new FileInputter(args[0]);
            IOutputFormatter outputter = new ConsoleOutputFormatter();
            GameController controller = new GameController();
            controller.PlayMultipleGenerations(inputter, outputter);
        }
예제 #4
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();
        }
예제 #5
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());
        }
예제 #6
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());
        }
예제 #7
0
        static void Main(string[] args)
        {
            CommandLine.Parser.Default.ParseArguments <Options>(args)
            .WithParsed(opts =>
            {
                if (!Directory.Exists(opts.WorkingDirectory))
                {
                    Console.Error.WriteLine($"Directory {opts.WorkingDirectory} is invalid.");
                    return;
                }

                string solutionPath = opts.SolutionPath;
                if (!Path.IsPathRooted(opts.SolutionPath))
                {
                    solutionPath = Path.Combine(opts.WorkingDirectory, opts.SolutionPath);
                }

                if (!File.Exists(solutionPath))
                {
                    Console.Error.WriteLine($"File {solutionPath} does not exist.");
                    return;
                }

                Console.WriteLine(CommandLine.Text.HeadingInfo.Default);
                Console.WriteLine(CommandLine.Text.CopyrightInfo.Default);
                Console.WriteLine();

                IOutputFormatter formatter = new ConsoleOutputFormatter();
                if (!string.IsNullOrEmpty(opts.OutputPath))
                {
                    formatter = new PrettyOutputFormatter(opts.OutputPath);
                }

                Console.WriteLine("Analyzing changes...");
                DateTime now = DateTime.Now;
                var provider = new GitSourceControlProvider(opts.WorkingDirectory);
                var analyzer = new Analyzer <string>(provider, solutionPath, opts.CommitId);
                analyzer.OpenSolution();

                formatter.WriteHeading(opts.SolutionPath, opts.CommitId, provider.GetTimestamp(opts.CommitId));

                var changedStyles = analyzer.GetChangedStyles();
                formatter.WriteChangedAssets("stylesheets", changedStyles);
                formatter.AppendSectionBreak();

                var changedScripts = analyzer.GetChangedScripts();
                formatter.WriteChangedAssets("JavaScripts", changedScripts);
                formatter.AppendSectionBreak();

                if (opts.IncludeChangedMethodSignatures)
                {
                    var changedMethods = analyzer.GetChangedMethodSignatures();
                    formatter.WriteChangedMethods(changedMethods);
                    formatter.AppendSectionBreak();
                }

                var referencingProjects = analyzer.GetReferencingProjects();
                formatter.WriteReferencingProjects(referencingProjects);

                formatter.WriteFooter();

                Console.WriteLine($"Elapsed time: {DateTime.Now - now}");
            });
        }