Skip to content

Commit 7da601c

Browse files
committed
修改命令行算法和文件收集算法,使命令行工具能正确工作
1 parent 8e6af90 commit 7da601c

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

CodeFormat/src/LuaWorkspaceFormat.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ bool LuaWorkspaceFormat::CheckWorkspace()
105105
void LuaWorkspaceFormat::CollectEditorconfig()
106106
{
107107
FileFinder finder(_workspace);
108-
finder.AddFindExtension(".editorconfig");
108+
finder.AddFindFile(".editorconfig");
109109
finder.AddIgnoreDirectory(".git");
110110
finder.AddIgnoreDirectory(".github");
111111
finder.AddIgnoreDirectory(".svn");

Util/src/CommandLine.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,18 @@ bool CommandLine::Parse(int argc, char** argv)
161161
commandOption.Value = _argvs[++index];
162162
commandOption.HasOption = true;
163163
}
164+
else if(index == argc - 1)
165+
{
166+
auto& commandOption = _options->_args.find(option)->second;
167+
if (commandOption.Type == CommandLineValueType::Boolean)
168+
{
169+
commandOption.Value = "true";
170+
commandOption.HasOption = true;
171+
continue;
172+
}
173+
return false;
174+
}
175+
164176
}
165177
return true;
166178
}

Util/src/FileFinder.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "Util/FileFinder.h"
22

33
FileFinder::FileFinder(std::filesystem::path root)
4-
:_root(root)
4+
: _root(root)
55
{
66
}
77

@@ -15,6 +15,11 @@ void FileFinder::AddFindExtension(const std::string& extension)
1515
_findExtension.insert(extension);
1616
}
1717

18+
void FileFinder::AddFindFile(const std::string& fileName)
19+
{
20+
_findFile.insert(fileName);
21+
}
22+
1823
std::vector<std::string> FileFinder::FindFiles()
1924
{
2025
std::vector<std::string> files;
@@ -36,16 +41,28 @@ void FileFinder::CollectFile(std::filesystem::path directoryPath, std::vector<st
3641
if (std::filesystem::is_directory(it.status()))
3742
{
3843
auto filename = it.path().filename().string();
39-
if (_ignoreDirectory.count(filename) == 0) {
44+
if (_ignoreDirectory.count(filename) == 0)
45+
{
4046
CollectFile(it.path(), paths);
4147
}
4248
}
43-
else if(std::filesystem::is_regular_file(it.status()))
49+
else if (std::filesystem::is_regular_file(it.status()))
4450
{
45-
std::string extension = it.path().extension().string();
46-
if(_findExtension.count(extension) == 1)
51+
if (!_findFile.empty())
52+
{
53+
auto filename = it.path().filename().string();
54+
if (_findFile.count(filename) == 1)
55+
{
56+
paths.push_back(it.path().string());
57+
}
58+
}
59+
if (!_findExtension.empty())
4760
{
48-
paths.push_back(it.path().string());
61+
std::string extension = it.path().extension().string();
62+
if (_findExtension.count(extension) == 1)
63+
{
64+
paths.push_back(it.path().string());
65+
}
4966
}
5067
}
5168
}

include/Util/FileFinder.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class FileFinder
1515

1616
void AddFindExtension(const std::string& extension);
1717

18+
void AddFindFile(const std::string& fileName);
19+
1820
std::vector<std::string> FindFiles();
1921

2022
private:
@@ -23,4 +25,5 @@ class FileFinder
2325
std::filesystem::path _root;
2426
std::set<std::string> _ignoreDirectory;
2527
std::set<std::string> _findExtension;
28+
std::set<std::string> _findFile;
2629
};

0 commit comments

Comments
 (0)