/// <summary> /// Parse the command line. /// </summary> public void ParseCommandLine(string[] inCommandLine) { CommandParser parser = new CommandParser("IncludeChecker", "[<file> ...]"); parser.AddCommandListener(this); parser.SetExitOnMissingArg(true, 1); parser.SetExtraHelpText("", @"Example: IncludeChecker -I c:\dev\foo\include -I c:\dev\bar\include -t r -t cr -T Ptr -T Ref test.cpp When using the --directory or -D option, it's possible to specify a wildcard: IncludeChecker -D include\*.h -I c:\dev\foo\include Sample configuration file: <devpal> <includechecker> <settings> <verbose/> <include_path>c:\dev\foo</include_path> <include_path>c:\dev\bar</include_path> <exclude_path>c:\dev\foo\include\precompiled.h</exclude_path> <exclude_path>c:\dev\bar\include\precompiled.h</exclude_path> <type_alias_prefix>r</type_alias_prefix> <type_alias_prefix>cr</type_alias_prefix> <type_alias_suffix>Ptr</type_alias_suffix> <type_alias_suffix>Ref</type_alias_suffix> </settings> </includechecker> </devpal>"); if (inCommandLine.Length == 0) { parser.Help(); System.Environment.Exit(-1); } parser.Parse(inCommandLine); if (sVersionOption.Matched) { Console.WriteLine("version " + IncludeChecker.Version); System.Environment.Exit(0); } if (sConfigFileOption.Matched) { string config_path = (string)sConfigFileOption.ArgValue; ReadConfigFile(config_path); } if (sVerboseOption.Matched) { // Command line overrides config file mConfig.Verbose = true; } if (parser.UnhandledArguments.Length == 0 && !sDirectoryOption.Matched) { WriteError("Error: no file or directory specified."); System.Environment.Exit(-1); } if (sDirectoryOption.Matched) { mStartDir = (string)sDirectoryOption.ArgValue; Verbose("Directory to check: " + mStartDir); } if (sXmlOutputOption.Matched) { mXmlOutputPath = (string)sXmlOutputOption.ArgValue; Verbose("Writing XML output to: " + mXmlOutputPath); } if (sIncludeOption.Matched) { foreach (string path in sIncludeOption.GetArgs()) { if (!System.IO.Directory.Exists(path)) { WriteLine("Warning: include directory " + path + " does not exist!"); ++mNrWarnings; } else { mConfig.AddIncludePath(path); Verbose("Command line: added include path " + path); } } } if (sExcludeOption.Matched) { foreach (string path in sExcludeOption.GetArgs()) { if (File.Exists(path) || Directory.Exists(path)) { mConfig.AddIgnorePath(path); Verbose("Command line: added exclude path " + path); } else { WriteError("Error: exclude path " + path + " does not exist!"); System.Environment.Exit(-1); } } } if (sInterfaceHeaderOption.Matched) { foreach (string path in sInterfaceHeaderOption.GetArgs()) { mConfig.InterfaceHeaders.Add(path); Verbose("Command line: added interface header " + path); } } if (sTypeAliasPrefixOption.Matched) { foreach (string prefix in sTypeAliasPrefixOption.GetArgs()) { mConfig.AddTypeAliasPrefix(prefix); Verbose("Command line: added type alias prefix '" + prefix + "'"); } } if (sTypeAliasSuffixOption.Matched) { foreach (string suffix in sTypeAliasSuffixOption.GetArgs()) { mConfig.AddTypeAliasSuffix(suffix); Verbose("Command line: added type alias suffix '" + suffix + "'"); } } if (string.IsNullOrEmpty(mConfig.CtagsPath)) { mConfig.CtagsPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\ctags\ctags.exe"; } Verbose(" ctags path is " + mConfig.CtagsPath); if (parser.UnhandledArguments.Length > 0) { foreach (string path in parser.UnhandledArguments) { if (File.Exists(path)) { Verbose("File to check: " + path); mStartFiles.Add(path); } else { string error = "Error: " + path + " is not a file."; if (Directory.Exists(path)) { error += " Please use --directory or -D (this will allow wildcards)."; } WriteError(error); System.Environment.Exit(-1); } } } }