Skip to content

Commit

Permalink
Add redirect for stdout to a file
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-lunarg committed Nov 3, 2024
1 parent f7b977a commit 2109b6b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void PrintUsage() {
<< std::endl
<< "Options:" << std::endl
<< " --help Display this message" << std::endl
<< " -o,--output Print output to file. [default: stdout]" << std::endl
<< " -y,--yaml Format output as YAML. [default: disabled]" << std::endl
<< " -v VERBOSITY Specify output verbosity (YAML output "
"only):"
Expand Down Expand Up @@ -80,6 +81,7 @@ void PrintUsage() {
int main(int argn, char** argv) {
ArgParser arg_parser;
arg_parser.AddFlag("h", "help", "");
arg_parser.AddOptionString("o", "output", "");
arg_parser.AddFlag("y", "yaml", "");
arg_parser.AddOptionInt("v", "verbosity", "", 0);
arg_parser.AddFlag("e", "entrypoint", "");
Expand All @@ -97,6 +99,12 @@ int main(int argn, char** argv) {
return EXIT_SUCCESS;
}

std::string output_file;
arg_parser.GetString("o", "output", &output_file);
if (!output_file.empty()) {
freopen(output_file.c_str(), "w", stdout);
}

bool output_as_yaml = arg_parser.GetFlag("y", "yaml");

int yaml_verbosity = 0;
Expand Down

0 comments on commit 2109b6b

Please sign in to comment.