Skip to content

Commit 51271ad

Browse files
committed
修改独立可执行格式化工具bug
1 parent 15fc3dd commit 51271ad

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

CodeFormat/src/CodeFormat.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ int main(int argc, char** argv)
2828
cmd.Add<int>("stdin", "i", "Read from stdin and specify read size");
2929
cmd.Add<std::string>("config", "c",
3030
"Specify editorconfig file, it decides on the effect of formatting or diagnosis");
31+
cmd.Add<std::string>("outfile", "o",
32+
"Specify output file");
3133

3234
if (!cmd.Parse(argc, argv))
3335
{
@@ -39,7 +41,7 @@ int main(int argc, char** argv)
3941

4042
if (!cmd.Get<std::string>("file").empty())
4143
{
42-
parser = LuaParser::LoadFromFile(argv[2]);
44+
parser = LuaParser::LoadFromFile(cmd.Get<std::string>("file"));
4345
}
4446
else if (cmd.Get<int>("stdin") != 0)
4547
{
@@ -68,7 +70,16 @@ int main(int argc, char** argv)
6870
if (cmd.GetTarget() == "format")
6971
{
7072
auto formattedText = formatter.GetFormattedText();
71-
std::cout.write(formattedText.data(), formattedText.size());
73+
if (!cmd.Get<std::string>("outfile").empty())
74+
{
75+
std::fstream f(cmd.Get<std::string>("outfile"), std::ios::out | std::ios::binary);
76+
f.write(formattedText.data(), formattedText.size());
77+
f.close();
78+
}
79+
else
80+
{
81+
std::cout.write(formattedText.data(), formattedText.size());
82+
}
7283
}
7384
else if (cmd.GetTarget() == "diagnosis")
7485
{

0 commit comments

Comments
 (0)