Skip to content

Commit 5e960e7

Browse files
authored
[projmgr] Extend filtering when listing templates and examples
1 parent 5625ff6 commit 5e960e7

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

tools/projmgr/include/ProjMgrWorker.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,13 @@ struct ExampleItem {
327327

328328
/**
329329
* @brief template item containing
330-
* name of example
330+
* name of template
331331
* description
332332
* path to the directory that contains the template
333333
* path to the *.csolution.yml file
334334
* path to copy the template into
335335
* pack identifier
336+
* placeholder symmetric to ExampleItem for reusable template
336337
*/
337338
struct TemplateItem {
338339
std::string name;
@@ -341,6 +342,7 @@ struct TemplateItem {
341342
std::string file;
342343
std::string copyTo;
343344
std::string pack;
345+
std::vector<BoardItem> boards;
344346
};
345347

346348
/**
@@ -1212,6 +1214,7 @@ class ProjMgrWorker {
12121214
bool IsBoardListCompatible(const ContextItem& context, const std::vector<RteBoard*> compatibleBoards, const Collection<RteItem*>& boards);
12131215
bool IsEnvironmentCompatible(const std::string& environment, const StrVec& filter);
12141216
bool HasCompatibleEnvironment(const Collection<RteItem*>& environments, const StrVec& filter);
1217+
template<class T> bool CheckFilter(const std::string& filter, const T& item);
12151218
};
12161219

12171220
#endif // PROJMGRWORKER_H

tools/projmgr/src/ProjMgrWorker.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4313,6 +4313,24 @@ std::vector<ExampleItem> ProjMgrWorker::CollectExamples(const ContextItem& conte
43134313
return examples;
43144314
}
43154315

4316+
template<class T> bool ProjMgrWorker::CheckFilter(const std::string& filter, const T& item) {
4317+
const bool nameFound = item.name.find(filter) != string::npos;
4318+
const bool packFound = item.pack.find(filter) != string::npos;
4319+
const bool descriptionFound = m_verbose ? item.description.find(filter) != string::npos : false;
4320+
bool boardFound = false;
4321+
if (m_verbose) {
4322+
for (const auto& board : item.boards) {
4323+
if (board.vendor.find(filter) != std::string::npos ||
4324+
board.name.find(filter) != std::string::npos ||
4325+
board.revision.find(filter) != std::string::npos) {
4326+
boardFound = true;
4327+
break;
4328+
}
4329+
}
4330+
}
4331+
return nameFound || packFound || descriptionFound || boardFound;
4332+
}
4333+
43164334
bool ProjMgrWorker::ListExamples(vector<string>& examples, const string& filter) {
43174335
const auto& selectedContext = m_selectedContexts.front();
43184336
ContextItem& context = m_contexts[selectedContext];
@@ -4331,7 +4349,7 @@ bool ProjMgrWorker::ListExamples(vector<string>& examples, const string& filter)
43314349
const auto& collectedExamples = CollectExamples(context, StrVec());
43324350

43334351
for (const auto& exampleItem : collectedExamples) {
4334-
if (!filter.empty() && exampleItem.name.find(filter) == string::npos) {
4352+
if (!filter.empty() && !CheckFilter(filter, exampleItem)) {
43354353
continue;
43364354
}
43374355
string example = exampleItem.boards.empty() ? "Reference Application: " : "";
@@ -4394,7 +4412,7 @@ bool ProjMgrWorker::ListTemplates(vector<string>& templates, const string& filte
43944412
}
43954413
const auto& collectedTemplates = CollectTemplates(context);
43964414
for (const auto& templateItem : collectedTemplates) {
4397-
if (!filter.empty() && templateItem.name.find(filter) == string::npos) {
4415+
if (!filter.empty() && !CheckFilter(filter, templateItem)) {
43984416
continue;
43994417
}
44004418
string templateStr = templateItem.name + " (" + templateItem.pack + ")";

tools/projmgr/test/src/ProjMgrUnitTests.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6879,7 +6879,7 @@ TEST_F(ProjMgrUnitTests, ListTargetSetsImageOnly) {
68796879
}
68806880

68816881
TEST_F(ProjMgrUnitTests, ListExamples) {
6882-
char* argv[8];
6882+
char* argv[9];
68836883
StdStreamRedirect streamRedirect;
68846884
const string& csolution = testinput_folder + "/Examples/solution.csolution.yml";
68856885

@@ -6940,6 +6940,17 @@ [email protected] (ARM::[email protected])\n\
69406940
69416941
");
69426942

6943+
// test with filter option (description)
6944+
streamRedirect.ClearStringStreams();
6945+
argv[7] = (char*)"different folder description";
6946+
argv[8] = (char*)"--verbose";
6947+
EXPECT_EQ(0, RunProjMgr(9, argv, 0));
6948+
outStr = streamRedirect.GetOutString();
6949+
EXPECT_TRUE(regex_search(outStr, regex("\
6950+
6951+
description: PreInclude Test Application with different folder description\n\
6952+
")));
6953+
69436954
// test with non-compatible device
69446955
streamRedirect.ClearStringStreams();
69456956
argv[5] = (char*)"CM0";
@@ -6974,6 +6985,17 @@ Board3 (ARM::[email protected])\n\
69746985
Board1Template (ARM::[email protected])\n\
69756986
");
69766987

6988+
// test filter (description)
6989+
argv[4] = (char*)"Template one";
6990+
argv[5] = (char*)"--verbose";
6991+
streamRedirect.ClearStringStreams();
6992+
EXPECT_EQ(0, RunProjMgr(6, argv, 0));
6993+
outStr = streamRedirect.GetOutString();
6994+
EXPECT_TRUE(regex_search(outStr, regex("\
6995+
Board1Template \\(ARM::[email protected]\\)\n\
6996+
description: \"Test board Template one\"\n\
6997+
")));
6998+
69776999
// list board's compatible template
69787000
const string& csolution = testinput_folder + "/Examples/solution.csolution.yml";
69797001
const string expected =

0 commit comments

Comments
 (0)