╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ fmt.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
368 } 369 370 // As a heuristic, we make enough capacity for the same as the input source. 371 fmt.out_buffer.clearRetainingCapacity(); 372 try fmt.out_buffer.ensureTotalCapacity(source_code.len); 373 374 tree.render(gpa, &fmt.out_buffer.writer, .{}) catch |err| switch (err) { 375 error.WriteFailed, error.OutOfMemory => return error.OutOfMemory, 376 }; 377 if (mem.eql(u8, fmt.out_buffer.written(), source_code)) 378 return; 379 380 if (check_mode) { 381 try fmt.stdout_writer.interface.print("{s}\n", .{file_path}); 382 fmt.any_error = true; 383 } else { 384 var af = try dir.createFileAtomic(io, sub_path, .{ .permissions = stat.permissions, .replace = true }); 385 defer af.deinit(io); 386 387 try af.file.writeStreamingAll(io, fmt.out_buffer.written()); 388 try af.replace(io); 389 try fmt.stdout_writer.interface.print("{s}\n", .{file_path}); 390 } 391 } 392 393 /// Provided for debugging/testing purposes; unused by the compiler. 394 pub fn main(init: process.Init) !void { 395 const args = try init.minimal.args.toSlice(init.arena.allocator()); 396 return run(init.gpa, init.arena.allocator(), init.io, args[1..]); 397 } 398