authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-12-28 13:29:37 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-12-28 13:29:37 -08:00
log7619f605fe17c34ff99ae95c0b0b4555ef7d912d
tree2cf374bd3117525fdd69398f319bf82875d2e5c7
parent9557477f4ccb8e487512c5a7c51df62ebade0606

cmd/init- ask about LICENSE before .gitignore


1 files changed, 19 insertions(+), 19 deletions(-)

src/cmd/init.zig+19-19
...@@ -74,25 +74,6 @@ pub fn execute(args: [][]u8) !void {...@@ -74,25 +74,6 @@ pub fn execute(args: [][]u8) !void {
74 },74 },
75 }75 }
7676
77 // ask about .gitignore
78 if (try u.does_folder_exist(".git")) {
79 const do = try inquirer.forConfirm(stdout, stdin, "It appears you're using git. Do you want init to add Zigmod to your .gitignore?", gpa);
80 if (do) {
81 const exists = try u.does_file_exist(null, ".gitignore");
82 const file: std.fs.File = try (if (exists) cwd.openFile(".gitignore", .{ .read = true, .write = true }) else cwd.createFile(".gitignore", .{}));
83 defer file.close();
84 const len = try file.getEndPos();
85 if (len > 0) try file.seekTo(len - 1);
86 const w = file.writer();
87 if (len > 0 and (try file.reader().readByte()) != '\n') {
88 try w.writeAll("\n");
89 }
90 if (!exists) try w.writeAll("zig-*\n");
91 try w.writeAll(".zigmod\n");
92 try w.writeAll("deps.zig\n");
93 }
94 }
95
96 // ask about LICENSE77 // ask about LICENSE
97 if (!(try u.does_file_exist(null, "LICENSE"))) {78 if (!(try u.does_file_exist(null, "LICENSE"))) {
98 if (detectlicense.licenses.find(license)) |text| {79 if (detectlicense.licenses.find(license)) |text| {
...@@ -120,6 +101,25 @@ pub fn execute(args: [][]u8) !void {...@@ -120,6 +101,25 @@ pub fn execute(args: [][]u8) !void {
120 }101 }
121 }102 }
122 }103 }
104
105 // ask about .gitignore
106 if (try u.does_folder_exist(".git")) {
107 const do = try inquirer.forConfirm(stdout, stdin, "It appears you're using git. Do you want init to add Zigmod to your .gitignore?", gpa);
108 if (do) {
109 const exists = try u.does_file_exist(null, ".gitignore");
110 const file: std.fs.File = try (if (exists) cwd.openFile(".gitignore", .{ .read = true, .write = true }) else cwd.createFile(".gitignore", .{}));
111 defer file.close();
112 const len = try file.getEndPos();
113 if (len > 0) try file.seekTo(len - 1);
114 const w = file.writer();
115 if (len > 0 and (try file.reader().readByte()) != '\n') {
116 try w.writeAll("\n");
117 }
118 if (!exists) try w.writeAll("zig-*\n");
119 try w.writeAll(".zigmod\n");
120 try w.writeAll("deps.zig\n");
121 }
122 }
123}123}
124124
125pub fn writeExeManifest(w: std.fs.File.Writer, id: string, name: string, license: ?string, description: ?string) !void {125pub fn writeExeManifest(w: std.fs.File.Writer, id: string, name: string, license: ?string, description: ?string) !void {