public static void Load_Names(CommandLine cmd) { cmd.AddAliases("names", "en"); cmd.Run(a => { foreach (var n in BibleStore.BibleStore.ChiBookNames) { var ma = BibleStore.BibleStore.RE_CHVERSE.Match(n.Value); if (ma != null) { var nm = new BibleName() { Id = n.Key, Volume = ma.Groups[1].Value.Trim().ToIntOrZero(), Suffix = ma.Groups[2].Value.TrimNullIfEmpty(), Full = n.Value, }; } } return(0); }); }
public static void Load_File(CommandLine cmd) { cmd.AddAliases("load", "import"); cmd.Run(a => { BibleStore.BibleStore.LoadNames("en", "data/en_names.yml"); BibleStore.BibleStore.LoadNames("zh", "data/zh_names.yml"); BibleStore.BibleStore.LoadOSIS("data/Chi-Union.xml"); BibleStore.BibleStore.LoadOSIS("data/NKJV.xml"); var r = BibleStore.BibleStore.FindEn("j 1:2"); foreach (var m in r.Matches) { Console.WriteLine($"Match: {m.BookName} {m.BookNames.Count.ToString()} {m.Chapter.ToString()}"); foreach (var v in m.Verses) { Console.WriteLine($"{v.Verse.ToString()}:"); foreach (var c in v.Content) { Console.WriteLine($" {c.Key}: {c.Value}"); } } } return(0); }); }
private static bool ParseCommandLine(string[] commandLineSegments) { Engine.CommandLine commandLine = new CommandLine(commandLineSegments); commandLine.AddAliases("--test-group", "--testgroup", "--test", "--tests"); commandLine.AddAliases("--show-nunit-output", "--shownunitoutput", "--show-nunit", "--shownunit"); commandLine.AddAliases("--pause-before-exit", "--pausebeforexit", "--pause"); commandLine.AddAliases("--pause-on-error", "--pauseonerror"); commandLine.AddAliases("--help", "-h", "-?"); string parameter, parameterAsEntered; bool isFirst = true; while (commandLine.IsInBounds) { // If the first segment isn't a parameter, it's the test group if (isFirst && !commandLine.IsOnParameter) { parameter = "--test-group"; parameterAsEntered = parameter; } else { if (!commandLine.GetParameter(out parameter, out parameterAsEntered)) { System.Console.Error.WriteLine("Unrecognized parameter \"" + parameterAsEntered + "\""); return(false); } } isFirst = false; // Test Group if (parameter == "--test-group") { if (!commandLine.GetBareWord(out testGroup)) { System.Console.Error.WriteLine("\"" + parameterAsEntered + "\" must be followed by a test group name"); return(false); } } // Show NUnit Output else if (parameter == "--show-nunit-output") { if (!commandLine.NoValue()) { System.Console.Error.WriteLine("\"" + parameterAsEntered + "\" can't be followed by a value"); return(false); } else { showNUnitOutput = true; } } // Pause Before Exit else if (parameter == "--pause-before-exit") { if (!commandLine.NoValue()) { System.Console.Error.WriteLine("\"" + parameterAsEntered + "\" can't be followed by a value"); return(false); } else { pauseBeforeExit = true; } } // Pause On Error else if (parameter == "--pause-on-error") { if (!commandLine.NoValue()) { System.Console.Error.WriteLine("\"" + parameterAsEntered + "\" can't be followed by a value"); return(false); } else { pauseOnError = true; } } // Help else if (parameter == "--help") { System.Console.WriteLine("TestRunner [group]. If no group is specified all tests will be run."); return(false); } // Everything else else { System.Console.Error.WriteLine("Unrecognized parameter \"" + parameterAsEntered + "\""); return(false); } } // Done. return(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); }