diff --git a/src/lib/parameters.cpp b/src/lib/parameters.cpp index 1aaa948..547bdd7 100644 --- a/src/lib/parameters.cpp +++ b/src/lib/parameters.cpp @@ -68,19 +68,26 @@ void AddFilesFromDatabase(Parameters& parameters, std::filesystem::path compile_ void Parameters::Parse(const std::filesystem::path& cccccRoot, int argc, char** argv) { - llvm::cl::list defines{ - "define", llvm::cl::desc("Specify define"), llvm::cl::value_desc("define")}; + llvm::cl::OptionCategory cccccCategory{"ccccc Options"}; + + llvm::cl::list defines{"define", + llvm::cl::desc("Specify define"), + llvm::cl::value_desc("define"), + llvm::cl::cat(cccccCategory)}; llvm::cl::alias defineAlias{ "D", llvm::cl::desc("Alias for -define"), llvm::cl::aliasopt(defines)}; llvm::cl::list extraOptions{ "extra-option", llvm::cl::desc("Extra option directly given to the clang parser"), - llvm::cl::value_desc("extra-option")}; + llvm::cl::value_desc("extra-option"), + llvm::cl::cat(cccccCategory)}; llvm::cl::alias extraAlias{ "e", llvm::cl::desc("Alias for -extra-option"), llvm::cl::aliasopt(extraOptions)}; - llvm::cl::list includes{ - "include-dir", llvm::cl::desc("Specify include path"), llvm::cl::value_desc("path")}; + llvm::cl::list includes{"include-dir", + llvm::cl::desc("Specify include path"), + llvm::cl::value_desc("path"), + llvm::cl::cat(cccccCategory)}; llvm::cl::alias includeAlias{ "I", llvm::cl::desc("Alias for -include-dir"), llvm::cl::aliasopt(includes)}; llvm::cl::opt templateFile{ @@ -88,23 +95,29 @@ void Parameters::Parse(const std::filesystem::path& cccccRoot, int argc, char** llvm::cl::desc( "template file to use for the report (default is template/html/template.tpl)"), llvm::cl::value_desc("template-file"), + llvm::cl::cat(cccccCategory), llvm::cl::init((cccccRoot / "template/html/template.tpl").string())}; - llvm::cl::alias includeTemplate{ + llvm::cl::alias templateFileAlias{ "t", llvm::cl::desc("Alias for -template-file"), llvm::cl::aliasopt(templateFile)}; - llvm::cl::opt pch{ - "pch", llvm::cl::desc("Compiled header path"), llvm::cl::value_desc("pch-file")}; + llvm::cl::opt pch{"pch", + llvm::cl::desc("Compiled header path"), + llvm::cl::value_desc("pch-file"), + llvm::cl::cat(cccccCategory)}; llvm::cl::opt sourceRoot{ "source-root", llvm::cl::desc("source root directory (filename display would be relative to that path) " "(default is current working directory)"), llvm::cl::value_desc("source-root"), + llvm::cl::cat(cccccCategory), llvm::cl::init(std::filesystem::current_path().string())}; llvm::cl::alias sourceRootAlias{ "R", llvm::cl::desc("Alias for -source-root"), llvm::cl::aliasopt(sourceRoot)}; - llvm::cl::list inputFilenames{ llvm::cl::Positional, llvm::cl::desc(""), llvm::cl::OneOrMore}; - llvm::cl::SetVersionPrinter(ShowVersion); + + HideUnrelatedOptions(cccccCategory); + + llvm::cl::AddExtraVersionPrinter(ShowVersion); llvm::cl::ParseCommandLineOptions( argc, argv, "Compute metrics from input files and output the report"); @@ -132,6 +145,19 @@ void Parameters::Parse(const std::filesystem::path& cccccRoot, int argc, char** } SetSourceRoot(std::string(sourceRoot)); SetTemplateFilename(std::string(templateFile)); + + defines.removeArgument(); + includes.removeArgument(); + inputFilenames.removeArgument(); + extraOptions.removeArgument(); + pch.removeArgument(); + sourceRoot.removeArgument(); + templateFile.removeArgument(); + defineAlias.removeArgument(); + includeAlias.removeArgument(); + extraAlias.removeArgument(); + sourceRootAlias.removeArgument(); + templateFileAlias.removeArgument(); } } // namespace ccccc diff --git a/test/test_parameters.cpp b/test/test_parameters.cpp index d4094bb..78b58ce 100644 --- a/test/test_parameters.cpp +++ b/test/test_parameters.cpp @@ -22,12 +22,6 @@ #include -template -static constexpr std::size_t ArraySize(const T (&)[N]) -{ - return N; -} - TEST_CASE("PARAMETERS_ADD_FILE") { const std::vector files{"a.c", "a.h", "b.c", "b.h"}; @@ -81,9 +75,6 @@ TEST_CASE("PARAMETERS_ADD_PCH") CHECK(pchFile == param.GetPch()); } -#if 0 // param.Parse is not reentrant :/ -// because of llvm::cl::ParseCommandLineOptions - TEST_CASE("PARAMETERS_PARSING_SHORT_OPTIONS") { const std::string cccccRoot = "."; @@ -119,7 +110,7 @@ TEST_CASE("PARAMETERS_PARSING_SHORT_OPTIONS") stringFiles[1].c_str()}; ccccc::Parameters param; - param.Parse(cccccRoot, ArraySize(argv), const_cast(argv)); + param.Parse(cccccRoot, std::size(argv), const_cast(argv)); CHECK(files == param.Filenames()); CHECK(includes == param.IncludePaths()); @@ -129,11 +120,6 @@ TEST_CASE("PARAMETERS_PARSING_SHORT_OPTIONS") CHECK(templateFile == param.GetTemplateFilename()); } -#endif - -#if 0 // param.Parse is not reentrant :/ -// because of llvm::cl::ParseCommandLineOptions - TEST_CASE("PARAMETERS_PARSING_LONG_OPTIONS") { const std::string cccccRoot = "."; @@ -169,7 +155,7 @@ TEST_CASE("PARAMETERS_PARSING_LONG_OPTIONS") stringFiles[1].c_str()}; ccccc::Parameters param; - param.Parse(cccccRoot, ArraySize(argv), const_cast(argv)); + param.Parse(cccccRoot, std::size(argv), const_cast(argv)); CHECK(files == param.Filenames()); CHECK(includes == param.IncludePaths()); @@ -178,4 +164,3 @@ TEST_CASE("PARAMETERS_PARSING_LONG_OPTIONS") CHECK(pchFile == param.GetPch()); CHECK(templateFile == param.GetTemplateFilename()); } -#endif