authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-07-29 04:59:20 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-07-29 04:59:20 -07:00
logca3781fe4e4ff41e642ef48a21095734ca6fd585
treecc1b5f415dcd442005877121ee669cb7ca33d973
parentd312857810eefe270ea5edb8f5517ce74c839d54

rewrite the init command


5 files changed, 113 insertions(+), 15 deletions(-)

deps.zig+31-1
......@@ -53,6 +53,11 @@ const dirs = struct {
5353 pub const _u9w9dpp6p804 = cache ++ "/git/github.com/MasterQ32/zig-uri";
5454 pub const _ocmr9rtohgcc = cache ++ "/git/github.com/nektro/zig-json";
5555 pub const _tnj3qf44tpeq = cache ++ "/git/github.com/nektro/zig-range";
56 pub const _2ovav391ivak = cache ++ "/git/github.com/nektro/zig-detect-license";
57 pub const _pt88y5d80m25 = cache ++ "/git/github.com/nektro/zig-licenses-text";
58 pub const _96h80ezrvj7i = cache ++ "/git/github.com/nektro/zig-leven";
59 pub const _qyrnfg0iwpzl = cache ++ "/git/github.com/nektro/zig-fs-check";
60 pub const _c1xirp1ota5p = cache ++ "/git/github.com/nektro/zig-inquirer";
5661 pub const _o6ogpor87xc2 = cache ++ "/git/github.com/marlersoft/zigwin32";
5762};
5863
......@@ -114,9 +119,34 @@ pub const package_data = struct {
114119 .pkg = Pkg{ .name = "range", .path = .{ .path = dirs._tnj3qf44tpeq ++ "/src/lib.zig" }, .dependencies = null },
115120 };
116121
122 pub const _pt88y5d80m25 = Package{
123 .directory = dirs._pt88y5d80m25,
124 .pkg = Pkg{ .name = "licenses-text", .path = .{ .path = dirs._pt88y5d80m25 ++ "/src/lib.zig" }, .dependencies = null },
125 };
126
127 pub const _96h80ezrvj7i = Package{
128 .directory = dirs._96h80ezrvj7i,
129 .pkg = Pkg{ .name = "leven", .path = .{ .path = dirs._96h80ezrvj7i ++ "/src/lib.zig" }, .dependencies = &.{_tnj3qf44tpeq.pkg.?} },
130 };
131
132 pub const _qyrnfg0iwpzl = Package{
133 .directory = dirs._qyrnfg0iwpzl,
134 .pkg = Pkg{ .name = "fs-check", .path = .{ .path = dirs._qyrnfg0iwpzl ++ "/src/lib.zig" }, .dependencies = null },
135 };
136
137 pub const _2ovav391ivak = Package{
138 .directory = dirs._2ovav391ivak,
139 .pkg = Pkg{ .name = "detect-license", .path = .{ .path = dirs._2ovav391ivak ++ "/src/lib.zig" }, .dependencies = &.{ _pt88y5d80m25.pkg.?, _96h80ezrvj7i.pkg.?, _qyrnfg0iwpzl.pkg.? } },
140 };
141
142 pub const _c1xirp1ota5p = Package{
143 .directory = dirs._c1xirp1ota5p,
144 .pkg = Pkg{ .name = "inquirer", .path = .{ .path = dirs._c1xirp1ota5p ++ "/src/lib.zig" }, .dependencies = &.{ _s84v9o48ucb0.pkg.?, _tnj3qf44tpeq.pkg.? } },
145 };
146
117147 pub const _89ujp8gq842x = Package{
118148 .directory = dirs._89ujp8gq842x,
119 .pkg = Pkg{ .name = "zigmod", .path = .{ .path = dirs._89ujp8gq842x ++ "/src/lib.zig" }, .dependencies = &.{ _s84v9o48ucb0.pkg.?, _2ta738wrqbaq.pkg.?, _0npcrzfdlrvk.pkg.?, _ejw82j2ipa0e.pkg.?, _ocmr9rtohgcc.pkg.?, _tnj3qf44tpeq.pkg.? } },
149 .pkg = Pkg{ .name = "zigmod", .path = .{ .path = dirs._89ujp8gq842x ++ "/src/lib.zig" }, .dependencies = &.{ _s84v9o48ucb0.pkg.?, _2ta738wrqbaq.pkg.?, _0npcrzfdlrvk.pkg.?, _ejw82j2ipa0e.pkg.?, _ocmr9rtohgcc.pkg.?, _tnj3qf44tpeq.pkg.?, _2ovav391ivak.pkg.?, _qyrnfg0iwpzl.pkg.?, _c1xirp1ota5p.pkg.? } },
120150 };
121151
122152 pub const _o6ogpor87xc2 = Package{
src/cmd/init.zig+67-12
......@@ -1,35 +1,90 @@
11const std = @import("std");
22const gpa = std.heap.c_allocator;
33
4const inquirer = @import("inquirer");
5const detectlicense = @import("detect-license");
46const u = @import("./../util/index.zig");
57
68//
79//
810
911pub fn execute(args: [][]u8) !void {
10 const name = u.detect_pkgname(u.try_index([]const u8, args, 0, ""), "") catch |err| switch (err) {
12 _ = args;
13
14 std.debug.print("This utility will walk you through creating a zig.mod file.\n", .{});
15 std.debug.print("That will give a good launching off point to get your next project started.\n", .{});
16 std.debug.print("Use `zigmod aq add <pkg>` to add a dependency from https://aquila.red/\n", .{});
17 std.debug.print("Press ^C at any time to quit.\n", .{});
18 std.debug.print("\n", .{});
19
20 const stdout = std.io.getStdOut().writer();
21 const stdin = std.io.getStdIn().reader();
22
23 const id = try inquirer.answer(stdout, "ID (this gets autogenerated):", []const u8, "{s}", try u.random_string(48));
24
25 const ptype = try inquirer.forEnum(stdout, stdin, "Are you making an application or a library?", gpa, enum { exe, lib }, null);
26
27 const name = try inquirer.forString(stdout, stdin, "package name:", gpa, u.detect_pkgname(u.try_index([]const u8, args, 0, ""), "") catch |err| switch (err) {
1128 error.NoBuildZig => {
1229 u.assert(false, "init requires a build.zig file", .{});
1330 unreachable;
1431 },
1532 else => return err,
16 };
17 const mainf = u.detct_mainfile(u.try_index([]const u8, args, 1, ""), null, name) catch |err| switch (err) {
33 });
34
35 const entry = if (ptype == .lib) try inquirer.forString(stdout, stdin, "package entry point:", gpa, u.detct_mainfile(u.try_index([]const u8, args, 1, ""), null, name) catch |err| switch (err) {
1836 error.CantFindMain => {
1937 u.assert(false, "unable to detect package entry point", .{});
2038 unreachable;
2139 },
2240 else => return err,
23 };
41 }) else null;
42
43 const license = try inquirer.forString(stdout, stdin, "license:", gpa, try detectlicense.detectInDir(gpa, std.fs.cwd()));
2444
25 const file = try std.fs.cwd().createFile("zig.mod", .{});
26 defer file.close();
45 const description = try inquirer.forString(stdout, stdin, "description:", gpa, null);
2746
28 const fwriter = file.writer();
29 try fwriter.print("id: {s}\n", .{u.random_string(48)});
30 try fwriter.print("name: {s}\n", .{name});
31 try fwriter.print("main: {s}\n", .{mainf});
32 try fwriter.print("dependencies:\n", .{});
47 std.debug.print("\n", .{});
48 std.debug.print("About to write local zig.mod:\n", .{});
49
50 std.debug.print("\n", .{});
51 switch (ptype) {
52 .exe => try writeExeManifest(stdout, id, name, license, description),
53 .lib => try writeLibManifest(stdout, id, name, entry.?, license, description),
54 }
55
56 std.debug.print("\n", .{});
57 switch (try inquirer.forConfirm(stdout, stdin, "Is this okay?", gpa)) {
58 false => {
59 std.debug.print("okay. quitting...", .{});
60 },
61 true => {
62 const file = try std.fs.cwd().createFile("zig.mod", .{});
63 defer file.close();
64 const w = file.writer();
65 switch (ptype) {
66 .exe => try writeExeManifest(w, id, name, license, description),
67 .lib => try writeLibManifest(w, id, name, entry.?, license, description),
68 }
69 std.debug.print("\n", .{});
70 u.print("Successfully initialized new package {s}!\n", .{name});
71 },
72 }
73}
74
75fn writeExeManifest(w: std.fs.File.Writer, id: []const u8, name: []const u8, license: []const u8, description: []const u8) !void {
76 try w.print("id: {s}\n", .{id});
77 try w.print("name: {s}\n", .{name});
78 try w.print("license: {s}\n", .{license});
79 try w.print("description: {s}\n", .{description});
80 try w.print("dev_dependencies:\n", .{});
81}
3382
34 u.print("Initialized a new package named {s} with entry point {s}", .{ name, mainf });
83fn writeLibManifest(w: std.fs.File.Writer, id: []const u8, name: []const u8, entry: []const u8, license: []const u8, description: []const u8) !void {
84 try w.print("id: {s}\n", .{id});
85 try w.print("name: {s}\n", .{name});
86 try w.print("main: {s}\n", .{entry});
87 try w.print("license: {s}\n", .{license});
88 try w.print("description: {s}\n", .{description});
89 try w.print("dependencies:\n", .{});
3590}
zig.mod+3
......@@ -35,6 +35,9 @@ dependencies:
3535 - src: git https://github.com/truemedian/zfetch
3636 - src: git https://github.com/nektro/zig-json
3737 - src: git https://github.com/nektro/zig-range
38 - src: git https://github.com/nektro/zig-detect-license
39 - src: git https://github.com/nektro/zig-fs-check
40 - src: git https://github.com/nektro/zig-inquirer
3841
3942dev_dependencies:
4043 - src: git https://github.com/marlersoft/zigwin32
zigmod.lock+6-1
......@@ -1,6 +1,6 @@
112
22git https://github.com/yaml/libyaml tag-0.2.5
3git https://github.com/nektro/zig-ansi commit-8ffadb65efdb424c6fe07a804107a775d55ebfe5
3git https://github.com/nektro/zig-ansi commit-d4a53bcac5b87abecc65491109ec22aaf5f3dc2f
44git https://github.com/ziglibs/known-folders commit-f5e5fb8370de41fbc220c0c0770d62bdf00530ea
55git https://github.com/nektro/zig-licenses commit-c9b8cbf3565675a056ad4e9b57cb4f84020e7680
66git https://github.com/truemedian/zfetch commit-8bbc7b34cd417794841e1432585334bc969dfe83
......@@ -10,4 +10,9 @@ git https://github.com/MasterQ32/zig-network commit-b9c91769d8ebd626c8e45b2abb05
1010git https://github.com/MasterQ32/zig-uri commit-52cdd2061bec0579519f0d30280597f3a1db8b75
1111git https://github.com/nektro/zig-json commit-72e555fbc0776f2600aee19b01e5ab1855ebec7a
1212git https://github.com/nektro/zig-range commit-890ca308fe09b3d5c866d5cfb3b3d7a95dbf939f
13git https://github.com/nektro/zig-detect-license commit-0ebd7d7c80b88fd5b606ee2ec57e9c6e23927fbf
14git https://github.com/nektro/zig-licenses-text commit-3c07c6e4eb0965dafd0b029c632f823631b3169c
15git https://github.com/nektro/zig-leven commit-8e9f827117ab1418578b692a2325754cc3ee692d
16git https://github.com/nektro/zig-fs-check commit-dcd8da90fcb8bf3c9887e713bf0ec072bc897dd5
17git https://github.com/nektro/zig-inquirer commit-d36621903868136b2ce347e9be9c937e664e1e74
1318git https://github.com/marlersoft/zigwin32 commit-ca6b8e5c378e31655fa11b886b44b62f703ef090
zigmod.sum+6-1
......@@ -1,5 +1,5 @@
11blake3-22472b867734926b202c055892fb0abb03f91556cd88998e2fe77addb003b1dd v/git/github.com/yaml/libyaml/tag-0.2.5
2blake3-f4e0cc5432c5d4532d7f69f935c0517b5e315934cdaff40e514b5375546f5756 git/github.com/nektro/zig-ansi
2blake3-3c76436cde156ef2b92eca8e2a38cc2e07f23055422cfe903585bab8bcc47dd9 git/github.com/nektro/zig-ansi
33blake3-35a1c330c9999876e71418a7d43ad24ca7d1e23c3b5576e5cb75667e3392cc10 git/github.com/ziglibs/known-folders
44blake3-42c3fae77ef41d2074e74de2d91cfc66bc591170494b10262dd2aeaea0b60cb5 git/github.com/nektro/zig-licenses
55blake3-e3072f7fb47e86d53c9a1879e254ba1af55941153fd5f6752ec659b2f14854c9 git/github.com/truemedian/zfetch
......@@ -9,4 +9,9 @@ blake3-21f91e48333ac0ca7f4704c96352831c25216e7056d02ce24de95d03fc942246 git/gith
99blake3-030ebb03f1ed21122e681b06786bea6f2f1b810e8eb9f2029d0eee4f4fb3103f git/github.com/MasterQ32/zig-uri
1010blake3-1893709ffc6359c5f9cd2f9409abccf78a94ed37bb2c6dd075c603356d17c94b git/github.com/nektro/zig-json
1111blake3-09698753782139ab4877d08f33235170836f68b73e482b65cdee5637a6addf86 git/github.com/nektro/zig-range
12blake3-e9e11cd5724286e0365ebdd5c17f35bcf75a4c1f6deb0060fc2e142ea0aa47bd git/github.com/nektro/zig-detect-license
13blake3-20ceb9e27bdb93540e93006628fb94e0540f3f69a2304a8f73ad2989b8e27226 git/github.com/nektro/zig-licenses-text
14blake3-cf68eaad66254b89c8bc18578f58607aa2e87ae59dd5696c2394eb5a0a31c455 git/github.com/nektro/zig-leven
15blake3-10460da714f5c8436d09c268795597b0b2686ffc1e789c9f50366c2cbb0e1ff3 git/github.com/nektro/zig-fs-check
16blake3-1cfc14f309d2dc8994bd8e2fc4e029cfee139ea2aef130a139bd996de3a538a8 git/github.com/nektro/zig-inquirer
1217blake3-949c3cd2c9e834190feeecb010c59ab5047fa721cfbdf67e0f0fd847194a6dad git/github.com/marlersoft/zigwin32