Esempio n. 1
0
        public void WhenHittingEscapeOnCommand_AssertCommandNameCleared()
        {
            ICommandCache commandCache = GenerateCommandCache();

            _commandingConsoleSubstitute.SetConsoleKeyInfoOrder(new[]
            {
                new ConsoleKeyInfo('C', ConsoleKey.C, true, false, false),
                new ConsoleKeyInfo('o', ConsoleKey.O, false, false, false),
                new ConsoleKeyInfo('m', ConsoleKey.M, false, false, false),
                new ConsoleKeyInfo('m', ConsoleKey.M, false, false, false),
                new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false),
                new ConsoleKeyInfo('n', ConsoleKey.N, false, false, false),
                new ConsoleKeyInfo('d', ConsoleKey.D, false, false, false),
                new ConsoleKeyInfo('\u0027', ConsoleKey.Escape, false, false, false),

                new ConsoleKeyInfo('\n', ConsoleKey.Enter, false, false, false),
            });

            var parser = new ConsoleCommandLineParser();
            ParseCommandLineResult result = parser.ParseCommandLine(commandCache, _commandingConsoleSubstitute);

            result.Command.ShouldBeNull();
            result.FlaggedParameters.ShouldBeEmpty();
            result.ValuedParameters.ShouldBeEmpty();
            result.RemainingText.ShouldBeEmpty();
        }
Esempio n. 2
0
        public void WhenCommandEnteredAndTabbingForParam_AssertParamShowed()
        {
            ICommandCache commandCache = GenerateCommandCache();

            _commandingConsoleSubstitute.SetConsoleKeyInfoOrder(new[]
            {
                new ConsoleKeyInfo('C', ConsoleKey.C, true, false, false),
                new ConsoleKeyInfo('o', ConsoleKey.O, false, false, false),
                new ConsoleKeyInfo('m', ConsoleKey.M, false, false, false),
                new ConsoleKeyInfo('m', ConsoleKey.M, false, false, false),
                new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false),
                new ConsoleKeyInfo('n', ConsoleKey.N, false, false, false),
                new ConsoleKeyInfo('d', ConsoleKey.D, false, false, false),
                new ConsoleKeyInfo('1', ConsoleKey.NumPad1, false, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.Spacebar, false, false, false),

                new ConsoleKeyInfo('\t', ConsoleKey.Tab, false, false, false),
                new ConsoleKeyInfo('\n', ConsoleKey.Enter, false, false, false),
            });

            var parser = new ConsoleCommandLineParser();
            ParseCommandLineResult result = parser.ParseCommandLine(commandCache, _commandingConsoleSubstitute);

            result.ThinkWeHaveSomething.ShouldBeTrue();
            result.Command.Name.ShouldBe("Command1");
            result.FlaggedParameters.ShouldBeEmpty();
            result.ValuedParameters.Single().Parameter.Name.ShouldBe("Param1");
            result.RemainingText.ShouldBeEmpty();
        }
Esempio n. 3
0
        public void WhenHittingEscapeOnParameterName_AssertParameterNameCleared()
        {
            ICommandCache commandCache = GenerateCommandCache();

            _commandingConsoleSubstitute.SetConsoleKeyInfoOrder(new[]
            {
                new ConsoleKeyInfo('C', ConsoleKey.C, true, false, false),
                new ConsoleKeyInfo('o', ConsoleKey.O, false, false, false),
                new ConsoleKeyInfo('m', ConsoleKey.M, false, false, false),
                new ConsoleKeyInfo('m', ConsoleKey.M, false, false, false),
                new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false),
                new ConsoleKeyInfo('n', ConsoleKey.N, false, false, false),
                new ConsoleKeyInfo('d', ConsoleKey.D, false, false, false),
                new ConsoleKeyInfo('1', ConsoleKey.NumPad1, false, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.Spacebar, false, false, false),

                new ConsoleKeyInfo('-', ConsoleKey.OemMinus, false, false, false),
                new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false),
                new ConsoleKeyInfo('b', ConsoleKey.B, false, false, false),
                new ConsoleKeyInfo('c', ConsoleKey.C, false, false, false),
                new ConsoleKeyInfo('\u0027', ConsoleKey.Escape, false, false, false),

                new ConsoleKeyInfo('\n', ConsoleKey.Enter, false, false, false),
            });

            var parser = new ConsoleCommandLineParser();
            ParseCommandLineResult result = parser.ParseCommandLine(commandCache, _commandingConsoleSubstitute);

            result.Command.Name.ShouldBe("Command1");
            result.FlaggedParameters.ShouldBeEmpty();
            result.ValuedParameters.ShouldBeEmpty();
            result.RemainingText.ShouldBeEmpty();
        }
Esempio n. 4
0
        public void WhenBackspacePressedManyTimes_AssertTextEmpty()
        {
            ICommandCache commandCache = GenerateCommandCache();

            _commandingConsoleSubstitute.SetConsoleKeyInfoOrder(new[]
            {
                new ConsoleKeyInfo('C', ConsoleKey.C, true, false, false),
                new ConsoleKeyInfo('o', ConsoleKey.O, false, false, false),
                new ConsoleKeyInfo('m', ConsoleKey.M, false, false, false),
                new ConsoleKeyInfo('m', ConsoleKey.M, false, false, false),
                new ConsoleKeyInfo('\b', ConsoleKey.Backspace, false, false, false),
                new ConsoleKeyInfo('\b', ConsoleKey.Backspace, false, false, false),
                new ConsoleKeyInfo('\b', ConsoleKey.Backspace, false, false, false),
                new ConsoleKeyInfo('\b', ConsoleKey.Backspace, false, false, false),
                new ConsoleKeyInfo('\b', ConsoleKey.Backspace, false, false, false),
                new ConsoleKeyInfo('\b', ConsoleKey.Backspace, false, false, false),
                new ConsoleKeyInfo('\b', ConsoleKey.Backspace, false, false, false),
                new ConsoleKeyInfo('\b', ConsoleKey.Backspace, false, false, false),
                new ConsoleKeyInfo('\b', ConsoleKey.Backspace, false, false, false),
                new ConsoleKeyInfo('\b', ConsoleKey.Backspace, false, false, false),
                new ConsoleKeyInfo('\b', ConsoleKey.Backspace, false, false, false),
                new ConsoleKeyInfo('\n', ConsoleKey.Enter, false, false, false),
            });

            var parser = new ConsoleCommandLineParser();
            ParseCommandLineResult result = parser.ParseCommandLine(commandCache, _commandingConsoleSubstitute);

            result.RemainingText.ShouldBeEmpty();
        }
Esempio n. 5
0
        public void WhenParsingInput_AssertDirectResult()
        {
            ICommandCache commandCache = GenerateCommandCache();

            _commandingConsoleSubstitute.SetConsoleKeyInfoOrder(new[]
            {
                new ConsoleKeyInfo('C', ConsoleKey.C, true, false, false),
                new ConsoleKeyInfo('o', ConsoleKey.O, false, false, false),
                new ConsoleKeyInfo('m', ConsoleKey.M, false, false, false),
                new ConsoleKeyInfo('m', ConsoleKey.M, false, false, false),
                new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false),
                new ConsoleKeyInfo('n', ConsoleKey.N, false, false, false),
                new ConsoleKeyInfo('d', ConsoleKey.D, false, false, false),
                new ConsoleKeyInfo('1', ConsoleKey.NumPad1, false, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.Spacebar, false, false, false),

                new ConsoleKeyInfo('-', ConsoleKey.OemMinus, false, false, false),
                new ConsoleKeyInfo('t', ConsoleKey.T, false, false, false),
                new ConsoleKeyInfo('\n', ConsoleKey.Enter, false, false, false),
            });

            var parser = new ConsoleCommandLineParser();
            ParseCommandLineResult result = parser.ParseCommandLine(commandCache, _commandingConsoleSubstitute);

            result.ThinkWeHaveSomething.ShouldBeTrue();
            result.Command.Name.ShouldBe("Command1");
            result.FlaggedParameters.ShouldBeEmpty();
            result.ValuedParameters.ShouldBeEmpty();
            result.RemainingText.ShouldBe("-t");
        }
Esempio n. 6
0
        public void WhenHittingEnterWithNothingEnteredIntoLine_AssertNotValid()
        {
            ICommandCache commandCache = GenerateCommandCache();

            _commandingConsoleSubstitute.SetConsoleKeyInfoOrder(new[]
            {
                new ConsoleKeyInfo('\n', ConsoleKey.Enter, false, false, false),
            });

            var parser = new ConsoleCommandLineParser();
            ParseCommandLineResult result = parser.ParseCommandLine(commandCache, _commandingConsoleSubstitute);

            result.ThinkWeHaveSomething.ShouldBeFalse();
        }
Esempio n. 7
0
        public void WhenParsingTabbedInputMultipleTimes_AssertTabResult()
        {
            ICommandCache commandCache = GenerateCommandCache();

            _commandingConsoleSubstitute.SetConsoleKeyInfoOrder(new[]
            {
                new ConsoleKeyInfo('C', ConsoleKey.C, true, false, false),
                new ConsoleKeyInfo('o', ConsoleKey.O, false, false, false),
                new ConsoleKeyInfo('m', ConsoleKey.M, false, false, false),
                new ConsoleKeyInfo('m', ConsoleKey.M, false, false, false),
                new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false),
                new ConsoleKeyInfo('n', ConsoleKey.N, false, false, false),
                new ConsoleKeyInfo('d', ConsoleKey.D, false, false, false),
                new ConsoleKeyInfo('1', ConsoleKey.NumPad1, false, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.Spacebar, false, false, false),

                new ConsoleKeyInfo('-', ConsoleKey.OemMinus, false, false, false),
                new ConsoleKeyInfo('p', ConsoleKey.T, false, false, false),
                new ConsoleKeyInfo('\t', ConsoleKey.Tab, false, false, false),
                new ConsoleKeyInfo('\t', ConsoleKey.Tab, false, false, false),
                new ConsoleKeyInfo('\t', ConsoleKey.Tab, false, false, false),

                new ConsoleKeyInfo('\t', ConsoleKey.Tab, false, false, false),
                new ConsoleKeyInfo('\t', ConsoleKey.Tab, false, false, false),
                new ConsoleKeyInfo('\t', ConsoleKey.Tab, false, false, false),

                new ConsoleKeyInfo('\t', ConsoleKey.Tab, false, false, false),
                new ConsoleKeyInfo('\t', ConsoleKey.Tab, false, false, false),
                new ConsoleKeyInfo('\t', ConsoleKey.Tab, false, false, false), // Tab a lot to make sure the rollover works

                new ConsoleKeyInfo(' ', ConsoleKey.Spacebar, false, false, false),
                new ConsoleKeyInfo('v', ConsoleKey.V, false, false, false),
                new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false),
                new ConsoleKeyInfo('l', ConsoleKey.L, false, false, false),
                new ConsoleKeyInfo('\n', ConsoleKey.Enter, false, false, false),
            });

            var parser = new ConsoleCommandLineParser();
            ParseCommandLineResult result = parser.ParseCommandLine(commandCache, _commandingConsoleSubstitute);

            result.ThinkWeHaveSomething.ShouldBeTrue();
            result.Command.Name.ShouldBe("Command1");
            result.FlaggedParameters.ShouldBeEmpty();
            result.ValuedParameters.Single().Parameter.Name.ShouldBe("Param3");
            result.ValuedParameters.Single().Value.ShouldBe("val");
            result.RemainingText.ShouldBeEmpty();
        }
Esempio n. 8
0
        public void WhenTabbingWithNoCommandEntered_AssertCommandInserted()
        {
            ICommandCache commandCache = GenerateCommandCache();

            _commandingConsoleSubstitute.SetConsoleKeyInfoOrder(new[]
            {
                new ConsoleKeyInfo('\t', ConsoleKey.Tab, false, false, false),
                new ConsoleKeyInfo('\n', ConsoleKey.Enter, false, false, false),
            });

            var parser = new ConsoleCommandLineParser();
            ParseCommandLineResult result = parser.ParseCommandLine(commandCache, _commandingConsoleSubstitute);

            result.ThinkWeHaveSomething.ShouldBeTrue();
            result.Command.Name.ShouldBe("Command1");
            result.FlaggedParameters.ShouldBeEmpty();
            result.ValuedParameters.ShouldBeEmpty();
            result.RemainingText.ShouldBeEmpty();
        }
Esempio n. 9
0
        public void WhenHittingTabButNothingToTabTo_AssertTextUnchanged()
        {
            ICommandCache commandCache = GenerateCommandCache();

            _commandingConsoleSubstitute.SetConsoleKeyInfoOrder(new[]
            {
                new ConsoleKeyInfo('C', ConsoleKey.C, true, false, false),
                new ConsoleKeyInfo('o', ConsoleKey.O, false, false, false),
                new ConsoleKeyInfo('m', ConsoleKey.M, false, false, false),
                new ConsoleKeyInfo('m', ConsoleKey.M, false, false, false),
                new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false),
                new ConsoleKeyInfo('n', ConsoleKey.N, false, false, false),
                new ConsoleKeyInfo('d', ConsoleKey.D, false, false, false),
                new ConsoleKeyInfo('1', ConsoleKey.NumPad1, false, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.Spacebar, false, false, false),

                new ConsoleKeyInfo('-', ConsoleKey.OemMinus, false, false, false),
                new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false),
                new ConsoleKeyInfo('\t', ConsoleKey.Tab, false, false, false),
                new ConsoleKeyInfo('\t', ConsoleKey.Tab, false, false, false),

                new ConsoleKeyInfo(' ', ConsoleKey.Spacebar, false, false, false),
                new ConsoleKeyInfo('v', ConsoleKey.V, false, false, false),
                new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false),
                new ConsoleKeyInfo('l', ConsoleKey.L, false, false, false),
                new ConsoleKeyInfo('\n', ConsoleKey.Enter, false, false, false),
            });

            var parser = new ConsoleCommandLineParser();
            ParseCommandLineResult result = parser.ParseCommandLine(commandCache, _commandingConsoleSubstitute);

            result.ThinkWeHaveSomething.ShouldBeTrue();
            result.Command.Name.ShouldBe("Command1");
            result.FlaggedParameters.ShouldBeEmpty();
            result.ValuedParameters.Single().Parameter.Name.ShouldBe("a");
            result.ValuedParameters.Single().Value.ShouldBe("val");
            result.RemainingText.ShouldBeEmpty();
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            var commandCache             = new CommandCache();
            var consoleCommandLineParser = new ConsoleCommandLineParser();
            var console = new CommandingConsole();

            InitCommands(commandCache);

            while (true)
            {
                Console.WriteLine("Enter a command: ");
                ParseCommandLineResult result = consoleCommandLineParser.ParseCommandLine(commandCache, console);

                if (!result.ThinkWeHaveSomething)
                {
                    Console.WriteLine("No command parsed from string: " + result.ToString());
                }
                else
                {
                    Console.WriteLine($"Chosen Command: {result.Command.Name}");

                    Console.WriteLine("Flagged Params:");
                    foreach (ParameterOption flaggedParam in result.FlaggedParameters)
                    {
                        Console.WriteLine($"\t{flaggedParam.Name}");
                    }

                    Console.WriteLine("Valued Params:");
                    foreach ((ParameterOption parameter, string value) in result.ValuedParameters)
                    {
                        Console.WriteLine($"\t{parameter.Name}: {value}");
                    }

                    Console.WriteLine($"Remaining Text: {result.RemainingText}");
                }
            }
        }
Esempio n. 11
0
		// Group: Primary Execution Paths
		// __________________________________________________________________________


		/* Function: Main
		 * The program entry point.
		 */
		public static void Main (string[] commandLine)
			{
			executionTimer = new ExecutionTimer();
			executionTimer.Start("Total Execution");

			engineInstance = null;

			quiet = false;
			workerThreadCount = DefaultWorkerThreadCount;
			totalFileChanges = 0;
			benchmark = false;
			pauseOnError = false;
			pauseBeforeExit = false;
			
			bool gracefulExit = false;

			var standardOutput = System.Console.Out;

			try
				{
				engineInstance = new NaturalDocs.Engine.Instance();
				
				ErrorList startupErrors = new ErrorList();
				ParseCommandLineResult parseCommandLineResult = ParseCommandLine(commandLine, out commandLineConfig, startupErrors);

				
				if (parseCommandLineResult == ParseCommandLineResult.Error)
					{
					HandleErrorList(startupErrors);
					}

				else if (parseCommandLineResult == ParseCommandLineResult.ShowCommandLineReference)
					{
					ShowCommandLineReference();
					gracefulExit = true;
					}

				else if (parseCommandLineResult == ParseCommandLineResult.ShowVersion)
					{
					ShowVersion();
					gracefulExit = true;
					}

				else // (parseCommandLineResult == ParseCommandLineResult.Run)
					{
					if (quiet)
						{  
						// This is easier and less error prone than putting conditional statements around all the non-error console
						// output, even if it's less efficient.
						System.Console.SetOut(System.IO.TextWriter.Null);
						}


					// Create project configuration files only

					if (commandLineConfig.ProjectConfigFolderPropertyLocation.IsDefined &&
						commandLineConfig.InputTargets.Count == 0 &&
						commandLineConfig.OutputTargets.Count == 0 &&
						!System.IO.File.Exists(commandLineConfig.ProjectConfigFolder + "/Project.txt"))
						{
						if (CreateProjectConfiguration(startupErrors))
							{  gracefulExit = true;  }
						else
							{  HandleErrorList(startupErrors);  }
						}


					// Normal execution

					else
						{
						if (BuildDocumentation(startupErrors))
							{  gracefulExit = true;  }
						else
							{  HandleErrorList(startupErrors);  }
						}
					}
				}

			catch (Exception e)
				{  
				HandleException(e);  
				}
				
			finally
				{
				Engine.Path projectFolder = engineInstance.Config.ProjectConfigFolder;

				engineInstance.Dispose(gracefulExit);
				engineInstance = null;

				executionTimer.End("Total Execution");

				if (benchmark)
					{  ShowBenchmarksAndBuildCSV(projectFolder + "/Benchmarks.csv");  } 

				// Restore the standard output.  We do this before "Press any key to continue" because we never want that to
				// be hidden.
				if (quiet)
					{  System.Console.SetOut(standardOutput);  }
				}
				
			if (pauseBeforeExit || (pauseOnError && !gracefulExit))
				{
				System.Console.WriteLine();
				System.Console.WriteLine(
					Engine.Locale.SafeGet("NaturalDocs.CLI", "Status.PressAnyKeyToContinue", "Press any key to continue...")
					);
				System.Console.ReadKey(true);
				}
			}
        /* Function: ParseCommandLine
         *
         * Parses the command line and applies the relevant settings in in <NaturalDocs.Engine's> modules.  If there were
         * errors they will be placed on errorList and it will return <ParseCommandLineResult.Error>.
         *
         * Supported:
         *
         *		- -i, --input, --source
         *		- -o, --output
         *		- -p, --project, --project-config --project-configuration
         *		- -w, --data, --working-data
         *		- -xi, --exclude-input, --exclude-source
         *		- -xip, --exclude-input-pattern, --exclude-source-pattern
         *		- -img, --images
         *		- -t, --tab, --tab-width, --tab-length
         *		- -do, --documented-only
         *		- -nag, --no-auto-group
         *		- -s, --style
         *		- -r, --rebuild
         *		- -ro, --rebuild-output
         *		- -q, --quiet
         *		- -v, --version
         *		- -vs, --versions, --all-versions
         *		- --benchmark
         *		- --worker-threads, --threads
         *		- --pause-before-exit, --pause
         *		- --pause-on-error
         *		- --dont-shrink-files
         *		- -h, --help
         *		- -?
         *
         * No Longer Supported:
         *
         *		- -cs, --char-set, --charset, --character-set, --characterset
         *		- -ho, --headers-only, --headersonly
         *		- -ag, --auto-group, --autogroup
         */
        private static ParseCommandLineResult ParseCommandLine(string[] commandLineSegments, out ProjectConfig commandLineConfig, ErrorList errorList)
        {
            int originalErrorCount        = errorList.Count;
            ParseCommandLineResult result = ParseCommandLineResult.Run;

            Engine.CommandLine commandLine = new CommandLine(commandLineSegments);

            commandLine.AddAliases("--input", "-i", "--source");
            commandLine.AddAliases("--output", "-o");
            commandLine.AddAliases("--project", "-p", "--project-config", "--projectconfig", "--project-configuration", "--projectconfiguration");
            commandLine.AddAliases("--working-data", "-w", "--data", "--workingdata");
            commandLine.AddAliases("--exclude-input", "-xi", "--excludeinput", "--exclude-source", "--excludesource");
            commandLine.AddAliases("--exclude-input-pattern", "-xip", "--excludeinputpattern", "--exclude-source-pattern", "--excludesourcepattern");
            commandLine.AddAliases("--images", "-img");
            commandLine.AddAliases("--tab-width", "-t", "--tab", "--tabwidth", "--tab-length", "--tablength");
            commandLine.AddAliases("--documented-only", "-do", "--documentedonly");
            commandLine.AddAliases("--no-auto-group", "-nag", "--noautogroup");
            commandLine.AddAliases("--style", "-s");
            commandLine.AddAliases("--rebuild", "-r");
            commandLine.AddAliases("--rebuild-output", "-ro", "--rebuildoutput");
            commandLine.AddAliases("--quiet", "-q");
            commandLine.AddAliases("--version", "-v");
            commandLine.AddAliases("--all-versions", "-vs", "--versions", "--allversions");
            commandLine.AddAliases("--pause-before-exit", "--pausebeforexit", "--pause");
            commandLine.AddAliases("--pause-on-error", "--pauseonerror");
            commandLine.AddAliases("--dont-shrink-files", "--dontshrinkfiles", "--dont-shrink-output", "--dontshrinkoutput", "--dont-shrink", "--dontshrink");
            commandLine.AddAliases("--worker-threads", "--threads");
            // no aliases for --benchmark
            commandLine.AddAliases("--help", "-h", "-?");

            // No longer supported
            commandLine.AddAliases("--charset", "-cs", "--char-set", "--character-set", "--characterset");
            commandLine.AddAliases("--headers-only", "-ho", "--headersonly");
            commandLine.AddAliases("--auto-group", "-ag", "--autogroup");

            commandLineConfig = new ProjectConfig(PropertySource.CommandLine);

            string parameter, parameterAsEntered;
            bool   isFirst = true;

            while (commandLine.IsInBounds)
            {
                // If the first segment isn't a parameter, assume it's the project folder specified without -p.
                if (isFirst && !commandLine.IsOnParameter)
                {
                    parameter          = "--project";
                    parameterAsEntered = parameter;
                }
                else if (!commandLine.GetParameter(out parameter, out parameterAsEntered))
                {
                    string bareWord;
                    commandLine.GetBareWord(out bareWord);

                    errorList.Add(
                        Locale.Get("NaturalDocs.CLI", "CommandLine.UnrecognizedParameter(param)", bareWord)
                        );

                    commandLine.SkipToNextParameter();
                    continue;
                }



                // Source folders

                if (parameter == "--input")
                {
                    Path folder;

                    if (!commandLine.GetPathValue(out folder))
                    {
                        errorList.Add(
                            Locale.Get("NaturalDocs.CLI", "CommandLine.ExpectedFolder(param)", parameterAsEntered)
                            );

                        commandLine.SkipToNextParameter();
                    }
                    else
                    {
                        if (folder.IsRelative)
                        {
                            folder = System.Environment.CurrentDirectory + "/" + folder;
                        }

                        var target = new Engine.Config.Targets.SourceFolder(PropertySource.CommandLine);

                        target.Folder = folder;
                        target.FolderPropertyLocation = PropertySource.CommandLine;

                        commandLineConfig.InputTargets.Add(target);
                    }
                }



                // Output folders

                else if (parameter == "--output")
                {
                    string format;
                    Path   folder;

                    if (!commandLine.GetBareWordAndPathValue(out format, out folder))
                    {
                        errorList.Add(
                            Locale.Get("NaturalDocs.CLI", "CommandLine.ExpectedFormatAndFolder(param)", parameter)
                            );

                        commandLine.SkipToNextParameter();
                    }
                    else
                    {
                        if (folder.IsRelative)
                        {
                            folder = System.Environment.CurrentDirectory + "/" + folder;
                        }

                        format = format.ToLower();

                        if (format == "html" || format == "framedhtml")
                        {
                            var target = new Engine.Config.Targets.HTMLOutputFolder(PropertySource.CommandLine);

                            target.Folder = folder;
                            target.FolderPropertyLocation = PropertySource.CommandLine;

                            commandLineConfig.OutputTargets.Add(target);
                        }
                        else
                        {
                            errorList.Add(
                                Locale.Get("NaturalDocs.CLI", "CommandLine.UnrecognizedOutputFormat(format)", format)
                                );

                            commandLine.SkipToNextParameter();
                        }
                    }
                }



                // Project configuration folder

                else if (parameter == "--project")
                {
                    Path folder;

                    if (!commandLine.GetPathValue(out folder))
                    {
                        errorList.Add(
                            Locale.Get("NaturalDocs.CLI", "CommandLine.ExpectedFolder(param)", parameterAsEntered)
                            );

                        commandLine.SkipToNextParameter();
                    }
                    else
                    {
                        if (folder.IsRelative)
                        {
                            folder = System.Environment.CurrentDirectory + "/" + folder;
                        }

                        // Accept the parameter being set to Project.txt instead of the folder.
                        if (folder.NameWithoutPath.ToLower() == "project.txt")
                        {
                            folder = folder.ParentFolder;
                        }

                        if (commandLineConfig.ProjectConfigFolderPropertyLocation.IsDefined)
                        {
                            errorList.Add(
                                Locale.Get("NaturalDocs.CLI", "CommandLine.OnlyOneProjectConfigFolder")
                                );
                        }
                        else
                        {
                            commandLineConfig.ProjectConfigFolder = folder;
                            commandLineConfig.ProjectConfigFolderPropertyLocation = PropertySource.CommandLine;
                        }
                    }
                }



                // Working data folder

                else if (parameter == "--working-data")
                {
                    Path folder;

                    if (!commandLine.GetPathValue(out folder))
                    {
                        errorList.Add(
                            Locale.Get("NaturalDocs.CLI", "CommandLine.ExpectedFolder(param)", parameterAsEntered)
                            );

                        commandLine.SkipToNextParameter();
                    }
                    else
                    {
                        if (folder.IsRelative)
                        {
                            folder = System.Environment.CurrentDirectory + "/" + folder;
                        }

                        if (commandLineConfig.WorkingDataFolderPropertyLocation.IsDefined)
                        {
                            errorList.Add(
                                Locale.Get("NaturalDocs.CLI", "CommandLine.OnlyOneWorkingDataFolder")
                                );
                        }
                        else
                        {
                            commandLineConfig.WorkingDataFolder = folder;
                            commandLineConfig.WorkingDataFolderPropertyLocation = PropertySource.CommandLine;
                        }
                    }
                }



                // Ignored input folders

                else if (parameter == "--exclude-input")
                {
                    Path folder;

                    if (!commandLine.GetPathValue(out folder))
                    {
                        errorList.Add(
                            Locale.Get("NaturalDocs.CLI", "CommandLine.ExpectedFolder(param)", parameterAsEntered)
                            );

                        commandLine.SkipToNextParameter();
                    }
                    else
                    {
                        if (folder.IsRelative)
                        {
                            folder = System.Environment.CurrentDirectory + "/" + folder;
                        }

                        var target = new Engine.Config.Targets.IgnoredSourceFolder(PropertySource.CommandLine);

                        target.Folder = folder;
                        target.FolderPropertyLocation = PropertySource.CommandLine;

                        commandLineConfig.FilterTargets.Add(target);
                    }
                }



                // Ignored input folder patterns

                else if (parameter == "--exclude-input-pattern")
                {
                    string pattern;

                    if (!commandLine.GetBareOrQuotedWordsValue(out pattern))
                    {
                        errorList.Add(
                            Engine.Locale.Get("NaturalDocs.CLI", "CommandLine.ExpectedPattern(param)", parameterAsEntered)
                            );

                        commandLine.SkipToNextParameter();
                    }
                    else
                    {
                        var target = new Engine.Config.Targets.IgnoredSourceFolderPattern(PropertySource.CommandLine);

                        target.Pattern = pattern;
                        target.PatternPropertyLocation = PropertySource.CommandLine;

                        commandLineConfig.FilterTargets.Add(target);
                    }
                }



                // Image folders

                else if (parameter == "--images")
                {
                    Path folder;

                    if (!commandLine.GetPathValue(out folder))
                    {
                        errorList.Add(
                            Locale.Get("NaturalDocs.CLI", "CommandLine.ExpectedFolder(param)", parameterAsEntered)
                            );

                        commandLine.SkipToNextParameter();
                    }
                    else
                    {
                        if (folder.IsRelative)
                        {
                            folder = System.Environment.CurrentDirectory + "/" + folder;
                        }

                        var target = new Engine.Config.Targets.ImageFolder(PropertySource.CommandLine);

                        target.Folder = folder;
                        target.FolderPropertyLocation = PropertySource.CommandLine;

                        commandLineConfig.InputTargets.Add(target);
                    }
                }



                // Tab Width

                else if (parameter == "--tab-width")
                {
                    int tabWidth;

                    if (!commandLine.GetIntegerValue(out tabWidth))
                    {
                        errorList.Add(
                            Locale.Get("NaturalDocs.CLI", "CommandLine.ExpectedNumber(param)", parameterAsEntered)
                            );

                        commandLine.SkipToNextParameter();
                    }
                    else if (tabWidth < 1)
                    {
                        errorList.Add(
                            Locale.Get("NaturalDocs.CLI", "CommandLine.InvalidTabWidth")
                            );

                        commandLine.SkipToNextParameter();
                    }
                    else
                    {
                        commandLineConfig.TabWidth = tabWidth;
                        commandLineConfig.TabWidthPropertyLocation = PropertySource.CommandLine;
                    }
                }

                // Support the -t4 form ini addition to -t 4.  Doesn't support --tablength4.
                else if (parameter.StartsWith("-t") && parameter.Length > 2 && parameter[2] >= '0' && parameter[2] <= '9')
                {
                    string tabWidthString = parameter.Substring(2);

                    int tabWidth;

                    if (!Int32.TryParse(tabWidthString, out tabWidth))
                    {
                        errorList.Add(
                            Locale.Get("NaturalDocs.CLI", "CommandLine.ExpectedNumber(param)", "-t")
                            );

                        commandLine.SkipToNextParameter();
                    }
                    else if (tabWidth < 1)
                    {
                        errorList.Add(
                            Locale.Get("NaturalDocs.CLI", "CommandLine.InvalidTabWidth")
                            );

                        commandLine.SkipToNextParameter();
                    }
                    else if (!commandLine.NoValue())
                    {
                        errorList.Add(
                            Locale.Get("NaturalDocs.CLI", "CommandLine.ExpectedNoValue(param)", parameterAsEntered)
                            );

                        commandLine.SkipToNextParameter();
                    }
                    else
                    {
                        commandLineConfig.TabWidth = tabWidth;
                        commandLineConfig.TabWidthPropertyLocation = PropertySource.CommandLine;
                    }
                }



                // Documented Only

                else if (parameter == "--documented-only")
                {
                    if (!commandLine.NoValue())
                    {
                        errorList.Add(
                            Locale.Get("NaturalDocs.CLI", "CommandLine.ExpectedNoValue(param)", parameterAsEntered)
                            );

                        commandLine.SkipToNextParameter();
                    }
                    else
                    {
                        commandLineConfig.DocumentedOnly = true;
                        commandLineConfig.DocumentedOnlyPropertyLocation = PropertySource.CommandLine;
                    }
                }



                // No Auto-Group

                else if (parameter == "--no-auto-group")
                {
                    if (!commandLine.NoValue())
                    {
                        errorList.Add(
                            Locale.Get("NaturalDocs.CLI", "CommandLine.ExpectedNoValue(param)", parameterAsEntered)
                            );

                        commandLine.SkipToNextParameter();
                    }
                    else
                    {
                        commandLineConfig.AutoGroup = false;
                        commandLineConfig.AutoGroupPropertyLocation = PropertySource.CommandLine;
                    }
                }



                // Don't Shrink Files

                else if (parameter == "--dont-shrink-files")
                {
                    if (!commandLine.NoValue())
                    {
                        errorList.Add(
                            Locale.Get("NaturalDocs.CLI", "CommandLine.ExpectedNoValue(param)", parameterAsEntered)
                            );

                        commandLine.SkipToNextParameter();
                    }
                    else
                    {
                        commandLineConfig.ShrinkFiles = false;
                        commandLineConfig.ShrinkFilesPropertyLocation = PropertySource.CommandLine;
                    }
                }



                // Style

                else if (parameter == "--style")
                {
                    string styleName;

                    if (!commandLine.GetBareOrQuotedWordsValue(out styleName))
                    {
                        errorList.Add(
                            Locale.Get("NaturalDocs.CLI", "CommandLine.ExpectedStyleName(param)", parameterAsEntered)
                            );

                        commandLine.SkipToNextParameter();
                    }
                    else
                    {
                        commandLineConfig.ProjectInfo.StyleName = styleName;
                        commandLineConfig.ProjectInfo.StyleNamePropertyLocation = PropertySource.CommandLine;
                    }
                }



                // Rebuild

                else if (parameter == "--rebuild")
                {
                    if (!commandLine.NoValue())
                    {
                        errorList.Add(
                            Locale.Get("NaturalDocs.CLI", "CommandLine.ExpectedNoValue(param)", parameterAsEntered)
                            );

                        commandLine.SkipToNextParameter();
                    }
                    else
                    {
                        EngineInstance.Config.UserWantsEverythingRebuilt = true;
                    }
                }



                // Rebuild Output

                else if (parameter == "--rebuild-output")
                {
                    if (!commandLine.NoValue())
                    {
                        errorList.Add(
                            Locale.Get("NaturalDocs.CLI", "CommandLine.ExpectedNoValue(param)", parameterAsEntered)
                            );

                        commandLine.SkipToNextParameter();
                    }
                    else
                    {
                        EngineInstance.Config.UserWantsOutputRebuilt = true;
                    }
                }



                // Quiet

                else if (parameter == "--quiet")
                {
                    if (!commandLine.NoValue())
                    {
                        errorList.Add(
                            Locale.Get("NaturalDocs.CLI", "CommandLine.ExpectedNoValue(param)", parameterAsEntered)
                            );

                        commandLine.SkipToNextParameter();
                    }
                    else
                    {
                        quiet = true;
                    }
                }



                // Worker Threads

                else if (parameter == "--worker-threads")
                {
                    int value;

                    if (!commandLine.GetIntegerValue(out value))
                    {
                        errorList.Add(
                            Locale.Get("NaturalDocs.CLI", "CommandLine.ExpectedNumber(param)", parameterAsEntered)
                            );

                        commandLine.SkipToNextParameter();
                    }
                    else if (value < 1)
                    {
                        errorList.Add(
                            Locale.Get("NaturalDocs.CLI", "CommandLine.InvalidWorkerThreadCount")
                            );

                        commandLine.SkipToNextParameter();
                    }
                    else
                    {
                        workerThreadCount = value;
                    }
                }



                // Benchmark

                else if (parameter == "--benchmark")
                {
                    if (!commandLine.NoValue())
                    {
                        errorList.Add(
                            Locale.Get("NaturalDocs.CLI", "CommandLine.ExpectedNoValue(param)", parameterAsEntered)
                            );

                        commandLine.SkipToNextParameter();
                    }
                    else
                    {
                        benchmark = true;
                    }
                }



                // Pause Before Exit

                else if (parameter == "--pause-before-exit")
                {
                    if (!commandLine.NoValue())
                    {
                        errorList.Add(
                            Locale.Get("NaturalDocs.CLI", "CommandLine.ExpectedNoValue(param)", parameterAsEntered)
                            );

                        commandLine.SkipToNextParameter();
                    }
                    else
                    {
                        pauseBeforeExit = true;
                    }
                }



                // Pause on Error

                else if (parameter == "--pause-on-error")
                {
                    if (!commandLine.NoValue())
                    {
                        errorList.Add(
                            Locale.Get("NaturalDocs.CLI", "CommandLine.ExpectedNoValue(param)", parameterAsEntered)
                            );

                        commandLine.SkipToNextParameter();
                    }
                    else
                    {
                        pauseOnError = true;
                    }
                }



                // Help

                else if (parameter == "--help")
                {
                    result = ParseCommandLineResult.ShowCommandLineReference;
                }



                // Version

                else if (parameter == "--version")
                {
                    result = ParseCommandLineResult.ShowVersion;
                }



                // All Versions

                else if (parameter == "--all-versions")
                {
                    result = ParseCommandLineResult.ShowAllVersions;
                }



                // No longer supported parameters

                else if (parameter == "--charset" ||
                         parameter == "--headers-only" ||
                         parameter == "--auto-group")
                {
                    errorList.Add(
                        Locale.Get("NaturalDocs.CLI", "CommandLine.NoLongerSupported(param)", parameterAsEntered)
                        );

                    commandLine.SkipToNextParameter();
                }



                // Everything else

                else
                {
                    errorList.Add(
                        Locale.Get("NaturalDocs.CLI", "CommandLine.UnrecognizedParameter(param)", parameterAsEntered)
                        );

                    commandLine.SkipToNextParameter();
                }



                isFirst = false;
            }


            // Validation

            if (result == ParseCommandLineResult.Run &&
                !commandLineConfig.ProjectConfigFolderPropertyLocation.IsDefined)
            {
                errorList.Add(
                    Locale.Get("NaturalDocs.CLI", "CommandLine.NoProjectConfigFolder")
                    );
            }


            // Done.

            if (errorList.Count != originalErrorCount)
            {
                result = ParseCommandLineResult.Error;
            }

            return(result);
        }
Esempio n. 13
0
        public void WhenUsingDownArrowForPastResultsIsPressedALot_AssertDirectResult()
        {
            ICommandCache commandCache = GenerateCommandCache();

            _commandingConsoleSubstitute.SetConsoleKeyInfoOrder(new[]
            {
                new ConsoleKeyInfo('C', ConsoleKey.C, true, false, false),
                new ConsoleKeyInfo('o', ConsoleKey.O, false, false, false),
                new ConsoleKeyInfo('m', ConsoleKey.M, false, false, false),
                new ConsoleKeyInfo('m', ConsoleKey.M, false, false, false),
                new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false),
                new ConsoleKeyInfo('n', ConsoleKey.N, false, false, false),
                new ConsoleKeyInfo('d', ConsoleKey.D, false, false, false),
                new ConsoleKeyInfo('1', ConsoleKey.NumPad1, false, false, false),
                new ConsoleKeyInfo('\n', ConsoleKey.Enter, false, false, false),
            });

            //Type in Command1 10 times, meaning the entire history is filled with this one
            var parser = new ConsoleCommandLineParser();

            for (int i = 0; i < 10; i++)
            {
                parser.ParseCommandLine(commandCache, _commandingConsoleSubstitute);
                _commandingConsoleSubstitute.ResetNextKeyIndex();
            }

            _commandingConsoleSubstitute.SetConsoleKeyInfoOrder(new[]
            {
                new ConsoleKeyInfo('C', ConsoleKey.C, true, false, false),
                new ConsoleKeyInfo('o', ConsoleKey.O, false, false, false),
                new ConsoleKeyInfo('m', ConsoleKey.M, false, false, false),
                new ConsoleKeyInfo('m', ConsoleKey.M, false, false, false),
                new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false),
                new ConsoleKeyInfo('n', ConsoleKey.N, false, false, false),
                new ConsoleKeyInfo('d', ConsoleKey.D, false, false, false),
                new ConsoleKeyInfo('2', ConsoleKey.NumPad1, false, false, false),
                new ConsoleKeyInfo('\n', ConsoleKey.Enter, false, false, false),
            });

            //Type in Command2 one time, so only the first command in history buffer is Command2 and the rest are Command1
            for (int i = 0; i < 1; i++)
            {
                parser.ParseCommandLine(commandCache, _commandingConsoleSubstitute);
                _commandingConsoleSubstitute.ResetNextKeyIndex();
            }

            //Hit up arrow key 9 times. Meaning skip over the most recent Command2 and get Command1
            _commandingConsoleSubstitute.SetConsoleKeyInfoOrder(new[]
            {
                //Add a few misc characters to prove they're removed when using up arrow
                new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false),
                new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false),
                new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false),

                //Down arrow 10 times so it goes past the history buffer
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),

                //Down arrow 10 more times to go to the only instance of Command2 in the history buffer. The one at the front. Index 0
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo('\n', ConsoleKey.Enter, false, false, false),
            });

            ParseCommandLineResult finalResult = parser.ParseCommandLine(commandCache, _commandingConsoleSubstitute);

            finalResult.ThinkWeHaveSomething.ShouldBeTrue();
            finalResult.Command.Name.ShouldBe("Command2");
        }
Esempio n. 14
0
        public void WhenUsingPastResultsDownArrow_AssertDirectResult()
        {
            ICommandCache commandCache = GenerateCommandCache();

            _commandingConsoleSubstitute.SetConsoleKeyInfoOrder(new[]
            {
                new ConsoleKeyInfo('C', ConsoleKey.C, true, false, false),
                new ConsoleKeyInfo('o', ConsoleKey.O, false, false, false),
                new ConsoleKeyInfo('m', ConsoleKey.M, false, false, false),
                new ConsoleKeyInfo('m', ConsoleKey.M, false, false, false),
                new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false),
                new ConsoleKeyInfo('n', ConsoleKey.N, false, false, false),
                new ConsoleKeyInfo('d', ConsoleKey.D, false, false, false),
                new ConsoleKeyInfo('1', ConsoleKey.NumPad1, false, false, false),
                new ConsoleKeyInfo('\n', ConsoleKey.Enter, false, false, false),
            });

            //Type in Command1 10 times, meaning the entire history is filled with this one
            var parser = new ConsoleCommandLineParser();

            for (int i = 0; i < 10; i++)
            {
                parser.ParseCommandLine(commandCache, _commandingConsoleSubstitute);
                _commandingConsoleSubstitute.ResetNextKeyIndex();
            }

            _commandingConsoleSubstitute.SetConsoleKeyInfoOrder(new[]
            {
                new ConsoleKeyInfo('C', ConsoleKey.C, true, false, false),
                new ConsoleKeyInfo('o', ConsoleKey.O, false, false, false),
                new ConsoleKeyInfo('m', ConsoleKey.M, false, false, false),
                new ConsoleKeyInfo('m', ConsoleKey.M, false, false, false),
                new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false),
                new ConsoleKeyInfo('n', ConsoleKey.N, false, false, false),
                new ConsoleKeyInfo('d', ConsoleKey.D, false, false, false),
                new ConsoleKeyInfo('2', ConsoleKey.NumPad1, false, false, false),
                new ConsoleKeyInfo('\n', ConsoleKey.Enter, false, false, false),
            });

            //Type in Command2 3 times, so only the very last item is Command1
            for (int i = 0; i < 3; i++)
            {
                parser.ParseCommandLine(commandCache, _commandingConsoleSubstitute);
                _commandingConsoleSubstitute.ResetNextKeyIndex();
            }

            //Hit up down key 8 times. Meaning start looking at the end of the history buffer and end of on the last instance of Command2 typed in
            _commandingConsoleSubstitute.SetConsoleKeyInfoOrder(new[]
            {
                //Add a few misc characters to prove they're removed when using up arrow
                new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false),
                new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false),
                new ConsoleKeyInfo('a', ConsoleKey.A, false, false, false),

                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),
                new ConsoleKeyInfo(' ', ConsoleKey.DownArrow, true, false, false),

                new ConsoleKeyInfo('\n', ConsoleKey.Enter, false, false, false),
            });

            ParseCommandLineResult finalResult = parser.ParseCommandLine(commandCache, _commandingConsoleSubstitute);

            finalResult.ThinkWeHaveSomething.ShouldBeTrue();
            finalResult.Command.Name.ShouldBe("Command2");
        }