Skip to content

Commit f01f9bf

Browse files
committed
cmd/init: ask if zigmod should write the entry point
1 parent 36bd8b3 commit f01f9bf

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

src/cmd/init.zig

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,40 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
234234
}
235235
}
236236
}
237+
238+
// ask about main.zig / mod.zig
239+
if (!try extras.doesFileExist(null, entry orelse "main.zig")) {
240+
const do = try inquirer.forConfirm(stdout, stdin, "It looks like your entry point doesn't exist. Do you want Zigmod to generate it for you?", gpa);
241+
if (do) {
242+
const file = try cwd.createFile(entry orelse "main.zig", .{});
243+
defer file.close();
244+
const w = file.writer();
245+
switch (ptype) {
246+
.exe => {
247+
try w.print(
248+
\\const std = @import("std");
249+
\\const {s} = @import("{s}");
250+
\\
251+
\\pub fn main() void {{
252+
\\ //
253+
\\}}
254+
\\
255+
,
256+
.{
257+
flatname,
258+
name,
259+
},
260+
);
261+
},
262+
.lib => {
263+
try w.writeAll(
264+
\\const std = @import("std");
265+
\\
266+
);
267+
},
268+
}
269+
}
270+
}
237271
}
238272

239273
pub fn writeExeManifest(w: std.fs.File.Writer, id: string, name: string, license: ?string, description: ?string) !void {

0 commit comments

Comments
 (0)