Skip to content

Commit 2109b6b

Browse files
Add redirect for stdout to a file
1 parent f7b977a commit 2109b6b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ void PrintUsage() {
4040
<< std::endl
4141
<< "Options:" << std::endl
4242
<< " --help Display this message" << std::endl
43+
<< " -o,--output Print output to file. [default: stdout]" << std::endl
4344
<< " -y,--yaml Format output as YAML. [default: disabled]" << std::endl
4445
<< " -v VERBOSITY Specify output verbosity (YAML output "
4546
"only):"
@@ -80,6 +81,7 @@ void PrintUsage() {
8081
int main(int argn, char** argv) {
8182
ArgParser arg_parser;
8283
arg_parser.AddFlag("h", "help", "");
84+
arg_parser.AddOptionString("o", "output", "");
8385
arg_parser.AddFlag("y", "yaml", "");
8486
arg_parser.AddOptionInt("v", "verbosity", "", 0);
8587
arg_parser.AddFlag("e", "entrypoint", "");
@@ -97,6 +99,12 @@ int main(int argn, char** argv) {
9799
return EXIT_SUCCESS;
98100
}
99101

102+
std::string output_file;
103+
arg_parser.GetString("o", "output", &output_file);
104+
if (!output_file.empty()) {
105+
freopen(output_file.c_str(), "w", stdout);
106+
}
107+
100108
bool output_as_yaml = arg_parser.GetFlag("y", "yaml");
101109

102110
int yaml_verbosity = 0;

0 commit comments

Comments
 (0)