25int main(
int argc,
const char **argv) {
26 std::string inputFile;
27 std::string outputPath;
30 for (
int i = 1; i < argc; ++i) {
31 std::string arg = argv[i];
33 if (i + 1 < argc) outputPath = argv[++i];
34 else { std::cerr <<
"Error: -o requires a path.\n";
return 1; }
35 }
else if (arg ==
"--indent-size") {
36 if (i + 1 < argc) opt.
indentSize = std::stoul(argv[++i]);
37 else { std::cerr <<
"Error: --indent-size requires a number.\n";
return 1; }
38 }
else if (arg ==
"--indent-type") {
40 std::string type = argv[++i];
43 else { std::cerr <<
"Error: Invalid indent-type '" << type <<
"'.\n";
return 1; }
44 }
else { std::cerr <<
"Error: --indent-type requires space|tab.\n";
return 1; }
45 }
else if (arg ==
"--brace-style") {
47 std::string style = argv[++i];
50 else { std::cerr <<
"Error: Invalid brace-style '" << style <<
"'.\n";
return 1; }
51 }
else { std::cerr <<
"Error: --brace-style requires attached|newline.\n";
return 1; }
52 }
else if (arg ==
"--max-width") {
53 if (i + 1 < argc) opt.
maxWidth = std::stoul(argv[++i]);
54 else { std::cerr <<
"Error: --max-width requires a number.\n";
return 1; }
55 }
else if (arg ==
"-h" || arg ==
"--help") {
58 }
else if (!arg.starts_with(
"-")) {
59 if (inputFile.empty()) inputFile = arg;
60 else { std::cerr <<
"Error: Multiple input files specified.\n";
return 1; }
62 std::cerr <<
"Error: Unknown argument '" << arg <<
"'.\n";
68 if (inputFile.empty()) {
69 std::cerr <<
"Error: No input file provided.\n";
74 if (!fs::exists(inputFile)) {
75 std::cerr <<
"Error: Input file '" << inputFile <<
"' does not exist.\n";
80 std::ifstream ifs(inputFile, std::ios::binary);
82 std::cerr <<
"Error: Could not open input file '" << inputFile <<
"'.\n";
85 std::string content((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
96 std::cerr <<
"Error: Parsing failed for '" << inputFile <<
"'.\n";
100 if (outputPath.empty()) {
103 std::wcout << std::endl;
105 std::wofstream ofs(outputPath);
106 if (!ofs.is_open()) {
107 std::cerr <<
"Error: Could not open output file '" << outputPath <<
"'.\n";
114 std::cout <<
"Formatted output written to '" << outputPath <<
"'.\n";
117 }
catch (
const std::exception &e) {
118 std::cerr <<
"Error during formatting: " << e.what() << std::endl;