Skip to content

Commit 72b557d

Browse files
committed
修改cli工具,check信息将输出到stdout上
1 parent c352bb8 commit 72b557d

File tree

6 files changed

+21
-11
lines changed

6 files changed

+21
-11
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ option(BuildAsLuaLib "Build for lua dll" OFF)
88
option(BuildCodeFormat "Build CodeFormat" ON)
99
option(BuildCodeFormatServer "Build CodeFormatServer" ON)
1010
option(EnableTest "Test project" ON)
11-
option(BuildInWordsDictionary "Use BuildInWordsDictionary" ON)
1211

1312
if(APPLE)
1413
include(CheckCCompilerFlag)

CodeFormat/src/CodeFormat.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ int main(int argc, char** argv)
3636
);
3737
cmd.AddTarget("format")
3838
.Add<std::string>("file", "f", "Specify the input file")
39+
.Add<std::string>("overwrite", "ow", "Format overwrite the input file")
3940
.Add<std::string>("workspace", "w",
4041
"Specify workspace directory,if no input file is specified, bulk formatting is performed")
4142
.Add<int>("stdin", "i", "Read from stdin and specify read size")
@@ -71,6 +72,9 @@ int main(int argc, char** argv)
7172
"Use file wildcards to specify how to ignore files\n"
7273
"\t\tseparated by ';'"
7374
)
75+
// .Add<std::string>("output", "o",
76+
// "Diagnostic messages are output to file or standard io"
77+
// "\t\toptional filename/stdout/stderr, default is stderr")
7478
.EnableKeyValueArgs();
7579

7680

@@ -110,6 +114,10 @@ int main(int argc, char** argv)
110114
{
111115
luaFormat->SetOutputFile(cmd.Get<std::string>("outfile"));
112116
}
117+
else if (cmd.HasOption("overwrite"))
118+
{
119+
luaFormat->SetOutputFile(cmd.Get<std::string>("file"));
120+
}
113121

114122
if (cmd.Get<bool>("detect-config"))
115123
{

CodeFormat/src/LuaFormat.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,10 @@ bool LuaFormat::Check(std::string_view workspace, std::shared_ptr<CodeSpellCheck
155155
{
156156
auto errors = _parser->GetErrors();
157157

158-
std::cerr << Util::format("Check {}\t{} error", inputFile, errors.size()) << std::endl;
159-
158+
std::cout << Util::format("Check {}\t{} error", inputFile, errors.size()) << std::endl;
159+
auto luaFile = _parser->GetLuaFile();
160160
for (auto& error : errors)
161161
{
162-
auto luaFile = _parser->GetLuaFile();
163162
DiagnosisInspection(error.ErrorMessage, error.ErrorRange, luaFile, inputFile);
164163
}
165164

@@ -196,7 +195,7 @@ bool LuaFormat::Check(std::string_view workspace, std::shared_ptr<CodeSpellCheck
196195
auto diagnosis = ctx.GetDiagnosisInfos();
197196
if (!diagnosis.empty())
198197
{
199-
std::cerr << Util::format("Check {}\t{} warning", inputFile, diagnosis.size()) << std::endl;
198+
std::cout << Util::format("Check {}\t{} warning", inputFile, diagnosis.size()) << std::endl;
200199

201200
for (auto& d : diagnosis)
202201
{
@@ -222,6 +221,6 @@ void LuaFormat::DiagnosisInspection(std::string_view message, TextRange range, s
222221
auto startChar = file->GetColumn(range.StartOffset);
223222
auto endLine = file->GetLine(range.EndOffset);
224223
auto endChar = file->GetColumn(range.EndOffset);
225-
std::cerr << Util::format("{}({}:{} to {}:{}): {}", path, startLine + 1, startChar, endLine + 1, endChar,
224+
std::cout << Util::format("\t{}({}:{} to {}:{}): {}", path, startLine + 1, startChar, endLine + 1, endChar,
226225
message) << std::endl;
227226
}

CodeFormat/src/LuaWorkspaceFormat.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ void LuaWorkspaceFormat::SetKeyValues(std::map<std::string, std::string, std::le
6464
}
6565
}
6666

67+
// void LuaWorkspaceFormat::SetOutput(std::string_view out)
68+
// {
69+
// _output = out;
70+
// }
71+
6772
void LuaWorkspaceFormat::ReformatWorkspace()
6873
{
6974
if (_autoDetectConfig)

CodeFormat/src/LuaWorkspaceFormat.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class LuaWorkspaceFormat
2222

2323
void SetKeyValues(std::map<std::string, std::string, std::less<>>& keyValues);
2424

25+
// void SetOutput(std::string_view out);
26+
2527
void ReformatWorkspace();
2628

2729
bool CheckWorkspace();
@@ -35,4 +37,5 @@ class LuaWorkspaceFormat
3537
std::vector<std::pair<std::string, std::shared_ptr<LuaEditorConfig>>> _editorConfigVector;
3638
std::shared_ptr<LuaCodeStyleOptions> _defaultOptions;
3739
std::vector<std::string> _ignorePattern;
40+
// std::string _output;
3841
};

Util/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,4 @@ target_sources(Util
3535
)
3636

3737

38-
target_link_libraries(Util PUBLIC uriparser)
39-
40-
if(BuildInWordsDictionary)
41-
target_compile_definitions(Util PRIVATE -DUSE_BUILDIN_DICTIONARY)
42-
endif()
38+
target_link_libraries(Util PUBLIC uriparser)

0 commit comments

Comments
 (0)