@@ -59,17 +59,6 @@ namespace pl::cli::sub {
5959 return formatter->getName () == formatterName;
6060 });
6161
62- // If no output path was given, use the input path with the formatter's file extension
63- if (outputFilePath.empty ()) {
64- if (inputFilePath.empty ()) {
65- ::fmt::print (" Input file path is required if no output file path is specified!\n " );
66- std::exit (EXIT_FAILURE);
67- }
68-
69- outputFilePath = inputFilePath;
70- outputFilePath.replace_extension (" ." + formatter->getFileExtension ());
71- }
72-
7362 // Open input file
7463 wolv::io::File inputFile (inputFilePath, wolv::io::File::Mode::Read);
7564 if (!inputFilePath.empty () && !inputFile.isValid ()) {
@@ -117,14 +106,18 @@ namespace pl::cli::sub {
117106 // Call selected formatter to format the results
118107 auto result = formatter->format (runtime);
119108
120- // Write results to output file
121- wolv::io::File outputFile (outputFilePath, wolv::io::File::Mode::Create);
122- if (!outputFile.isValid ()) {
123- ::fmt::print (" Failed to create output file: {}\n " , outputFilePath.string());
124- std::exit (EXIT_FAILURE);
125- }
109+ if (outputFilePath.empty ()) {
110+ fwrite (result.data (), 1 , result.size (), stdout);
111+ } else {
112+ // Write results to output file
113+ wolv::io::File outputFile (outputFilePath, wolv::io::File::Mode::Create);
114+ if (!outputFile.isValid ()) {
115+ ::fmt::print (" Failed to create output file: {}\n " , outputFilePath.string());
116+ std::exit (EXIT_FAILURE);
117+ }
126118
127- outputFile.writeVector (result);
119+ outputFile.writeVector (result);
120+ }
128121 });
129122 }
130123
0 commit comments