| author | |
| committer | |
| log | cab0c439b89cebbbc87e5008e04605dd34ef45e6 |
| tree | 030632261c8cb2d8de89e572b5859a2223571a1a |
| parent | 9abce3b8daa89c643896d73ec8ff968a4b832abb |
2 files changed, 15 insertions(+), 0 deletions(-)
src/cmd_init.zig+1| ... | @@ -14,6 +14,7 @@ pub fn execute(args: [][]u8) !void { | ... | @@ -14,6 +14,7 @@ pub fn execute(args: [][]u8) !void { |
| 14 | defer file.close(); | 14 | defer file.close(); |
| 15 | 15 | ||
| 16 | const fwriter = file.writer(); | 16 | const fwriter = file.writer(); |
| 17 | try fwriter.print("id: {}\n", .{u.random_string(48)}); | ||
| 17 | try fwriter.print("name: {}\n", .{name}); | 18 | try fwriter.print("name: {}\n", .{name}); |
| 18 | try fwriter.print("main: {}\n", .{mainf}); | 19 | try fwriter.print("main: {}\n", .{mainf}); |
| 19 | try fwriter.print("dependencies:\n", .{}); | 20 | try fwriter.print("dependencies:\n", .{}); |
src/util/funcs.zig+14| ... | @@ -222,3 +222,17 @@ pub fn rm_recv(path: []const u8) anyerror!void { | ... | @@ -222,3 +222,17 @@ pub fn rm_recv(path: []const u8) anyerror!void { |
| 222 | try std.fs.deleteFileAbsolute(abs_path); | 222 | try std.fs.deleteFileAbsolute(abs_path); |
| 223 | } | 223 | } |
| 224 | } | 224 | } |
| 225 | |||
| 226 | const alphabet = "0123456789abcdefghijklmnopqrstuvwxyz"; | ||
| 227 | |||
| 228 | pub 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 | } |