authorgravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-12-15 02:29:29 -08:00
committergravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-12-15 02:29:29 -08:00
logcab0c439b89cebbbc87e5008e04605dd34ef45e6
tree030632261c8cb2d8de89e572b5859a2223571a1a
parent9abce3b8daa89c643896d73ec8ff968a4b832abb

closes #4


2 files changed, 15 insertions(+), 0 deletions(-)

src/cmd_init.zig+1
......@@ -14,6 +14,7 @@ pub fn execute(args: [][]u8) !void {
1414 defer file.close();
1515
1616 const fwriter = file.writer();
17 try fwriter.print("id: {}\n", .{u.random_string(48)});
1718 try fwriter.print("name: {}\n", .{name});
1819 try fwriter.print("main: {}\n", .{mainf});
1920 try fwriter.print("dependencies:\n", .{});
src/util/funcs.zig+14
......@@ -222,3 +222,17 @@ pub fn rm_recv(path: []const u8) anyerror!void {
222222 try std.fs.deleteFileAbsolute(abs_path);
223223 }
224224}
225
226const alphabet = "0123456789abcdefghijklmnopqrstuvwxyz";
227
228pub fn random_string(len: usize) ![]const u8 {
229 const now = @intCast(u64, std.time.nanoTimestamp());
230 var rand = std.rand.DefaultPrng.init(now);
231 const r = &rand.random;
232 var buf = try gpa.alloc(u8, len);
233 var i: usize = 0;
234 while (i < len) : (i += 1) {
235 buf[i] = alphabet[r.int(usize)%alphabet.len];
236 }
237 return buf;
238}