mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
This allows running commands that take an output directory argument. The main thing that was needed for this feature was generated file subpaths, to allow access to the files in a generated directory. Additionally, a minor change was required to so that the correct directory is created for output directory args.
19 lines
555 B
Zig
19 lines
555 B
Zig
const std = @import("std");
|
|
|
|
pub fn main() !void {
|
|
var args = try std.process.argsWithAllocator(std.heap.page_allocator);
|
|
_ = args.skip();
|
|
const dir_name = args.next().?;
|
|
const dir = try std.fs.cwd().openDir(if (std.mem.startsWith(u8, dir_name, "--dir="))
|
|
dir_name["--dir=".len..]
|
|
else
|
|
dir_name, .{});
|
|
const file_name = args.next().?;
|
|
const file = try dir.createFile(file_name, .{});
|
|
try file.writer().print(
|
|
\\{s}
|
|
\\{s}
|
|
\\Hello, world!
|
|
\\
|
|
, .{ dir_name, file_name });
|
|
}
|