Skip to content

Commit e133f8e

Browse files
committed
规范打印
1 parent 83b070c commit e133f8e

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Change Log
2+
## 0.9.6
23

4+
命令行工具帮助打印更规范
35
## 0.9.5
46

57
命令行工具在指定单输入文件时可以指定工作区,这可以帮助detect config。

CodeFormat/src/CodeFormat.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@
2424
int main(int argc, char** argv)
2525
{
2626
CommandLine cmd;
27-
27+
cmd.SetUsage(
28+
"Usage:\n"
29+
"CodeFormat [check/format] [options]\n"
30+
"for example:\n"
31+
"\tCodeFormat check -w . -d\n"
32+
"\tCodeFormat format -f test.lua -d\n"
33+
);
2834
cmd.AddTarget("format")
2935
.Add<std::string>("file", "f", "Specify the input file")
3036
.Add<std::string>("workspace", "w",
@@ -34,7 +40,7 @@ int main(int argc, char** argv)
3440
"Specify .editorconfig file, it decides on the effect of formatting")
3541
.Add<bool>("detect-config", "d",
3642
"Configuration will be automatically detected,\n"
37-
" If this option is set, the config option has no effect ")
43+
"\t\tIf this option is set, the config option has no effect ")
3844
.Add<std::string>("outfile", "o",
3945
"Specify output file")
4046
.EnableKeyValueArgs();
@@ -46,7 +52,7 @@ int main(int argc, char** argv)
4652
"Specify editorconfig file, it decides on the effect of formatting or diagnosis")
4753
.Add<bool>("detect-config", "d",
4854
"Configuration will be automatically detected,\n"
49-
" If this option is set, the config option has no effect")
55+
"\t\tIf this option is set, the config option has no effect")
5056
.Add<bool>("diagnosis-as-error", "DAE", "if exist error or diagnosis info , return -1")
5157
.EnableKeyValueArgs();
5258

Util/src/CommandLine.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ bool CommandLine::Parse(int argc, char** argv)
177177
return true;
178178
}
179179

180+
void CommandLine::SetUsage(std::string_view usage)
181+
{
182+
_usage = std::string(usage);
183+
}
184+
180185
void CommandLine::PrintUsage()
181186
{
182187
for (auto& error : _errors)
@@ -185,7 +190,7 @@ void CommandLine::PrintUsage()
185190
}
186191
std::cerr << std::endl;
187192

188-
std::cerr << "first param must be target:" << std::endl;
193+
std::cerr << _usage << std::endl;
189194
for (auto& target : _targets)
190195
{
191196
std::cerr << format("{}:", target.first) << std::endl;
@@ -196,7 +201,7 @@ void CommandLine::PrintUsage()
196201
auto& name = it.second;
197202
auto& option = options._args[name];
198203

199-
std::cerr << format(" -{} --{} {}",
204+
std::cerr << format("\t-{} --{}\n\t\t{}",
200205
shortName, name, option.Description) << std::endl;
201206
std::cerr << std::endl;
202207
}

include/Util/CommandLine.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,14 @@ class CommandLine
130130

131131
bool Parse(int argc, char** argv);
132132

133+
void SetUsage(std::string_view usage);
134+
133135
void PrintUsage();
134136
private:
135137
std::vector<std::string> _argvs;
136138
std::map<std::string, CommandLineTargetOptions, std::less<>> _targets;
137139
CommandLineTargetOptions* _options;
138140
std::string _currentTarget;
139141
std::vector<std::string> _errors;
142+
std::string _usage;
140143
};

0 commit comments

Comments
 (0)