| author | |
| committer | |
| log | 67caed05c15bee558beb29dd5f33d38cac874e89 |
| tree | ca7e3a29b230ff2a9a7440db0f9c94d70a353bb3 |
| parent | d2169e0ca9f2477017df633e2018d95986c696bb |
5 files changed, 15 insertions(+), 22 deletions(-)
src/cmd/aquila/install.zig+2-1| ... | @@ -2,6 +2,7 @@ const std = @import("std"); | ... | @@ -2,6 +2,7 @@ const std = @import("std"); |
| 2 | const string = []const u8; | 2 | const string = []const u8; |
| 3 | const gpa = std.heap.c_allocator; | 3 | const gpa = std.heap.c_allocator; |
| 4 | const knownfolders = @import("known-folders"); | 4 | const knownfolders = @import("known-folders"); |
| 5 | const extras = @import("extras"); | ||
| 5 | 6 | ||
| 6 | const zigmod = @import("../../lib.zig"); | 7 | const zigmod = @import("../../lib.zig"); |
| 7 | const u = @import("./../../util/index.zig"); | 8 | const u = @import("./../../util/index.zig"); |
| ... | @@ -12,7 +13,7 @@ pub fn execute(args: [][]u8) !void { | ... | @@ -12,7 +13,7 @@ pub fn execute(args: [][]u8) !void { |
| 12 | const homepath = home.?; | 13 | const homepath = home.?; |
| 13 | const homedir = try std.fs.cwd().openDir(homepath, .{}); | 14 | const homedir = try std.fs.cwd().openDir(homepath, .{}); |
| 14 | 15 | ||
| 15 | if (!(try u.does_file_exist(homedir, "zigmod.yml"))) { | 16 | if (!(try extras.doesFileExist(homedir, "zigmod.yml"))) { |
| 16 | const f = try homedir.createFile("zigmod.yml", .{}); | 17 | const f = try homedir.createFile("zigmod.yml", .{}); |
| 17 | defer f.close(); | 18 | defer f.close(); |
| 18 | const w = f.writer(); | 19 | const w = f.writer(); |
src/cmd/aquila/update.zig+2-1| ... | @@ -2,6 +2,7 @@ const std = @import("std"); | ... | @@ -2,6 +2,7 @@ const std = @import("std"); |
| 2 | const string = []const u8; | 2 | const string = []const u8; |
| 3 | const gpa = std.heap.c_allocator; | 3 | const gpa = std.heap.c_allocator; |
| 4 | const knownfolders = @import("known-folders"); | 4 | const knownfolders = @import("known-folders"); |
| 5 | const extras = @import("extras"); | ||
| 5 | 6 | ||
| 6 | const zigmod = @import("../../lib.zig"); | 7 | const zigmod = @import("../../lib.zig"); |
| 7 | const u = @import("./../../util/index.zig"); | 8 | const u = @import("./../../util/index.zig"); |
| ... | @@ -12,7 +13,7 @@ pub fn execute(args: [][]u8) !void { | ... | @@ -12,7 +13,7 @@ pub fn execute(args: [][]u8) !void { |
| 12 | const homepath = home.?; | 13 | const homepath = home.?; |
| 13 | const homedir = try std.fs.cwd().openDir(homepath, .{}); | 14 | const homedir = try std.fs.cwd().openDir(homepath, .{}); |
| 14 | 15 | ||
| 15 | if (!(try u.does_file_exist(homedir, "zigmod.yml"))) { | 16 | if (!(try extras.doesFileExist(homedir, "zigmod.yml"))) { |
| 16 | const f = try homedir.createFile("zigmod.yml", .{}); | 17 | const f = try homedir.createFile("zigmod.yml", .{}); |
| 17 | defer f.close(); | 18 | defer f.close(); |
| 18 | const w = f.writer(); | 19 | const w = f.writer(); |
src/cmd/init.zig+5-4| ... | @@ -6,6 +6,7 @@ const detectlicense = @import("detect-license"); | ... | @@ -6,6 +6,7 @@ const detectlicense = @import("detect-license"); |
| 6 | const knownfolders = @import("known-folders"); | 6 | const knownfolders = @import("known-folders"); |
| 7 | const ini = @import("ini"); | 7 | const ini = @import("ini"); |
| 8 | const time = @import("time"); | 8 | const time = @import("time"); |
| 9 | const extras = @import("extras"); | ||
| 9 | 10 | ||
| 10 | const u = @import("./../util/index.zig"); | 11 | const u = @import("./../util/index.zig"); |
| 11 | 12 | ||
| ... | @@ -72,7 +73,7 @@ pub fn execute(args: [][]u8) !void { | ... | @@ -72,7 +73,7 @@ pub fn execute(args: [][]u8) !void { |
| 72 | } | 73 | } |
| 73 | 74 | ||
| 74 | // ask about LICENSE | 75 | // ask about LICENSE |
| 75 | if (!(try u.does_file_exist(null, "LICENSE"))) { | 76 | if (!(try extras.doesFileExist(null, "LICENSE"))) { |
| 76 | if (detectlicense.licenses.find(license)) |text| { | 77 | if (detectlicense.licenses.find(license)) |text| { |
| 77 | if (try inquirer.forConfirm(stdout, stdin, "It appears you don't have a LICENSE file defined, would you like init to add it for you?", gpa)) { | 78 | if (try inquirer.forConfirm(stdout, stdin, "It appears you don't have a LICENSE file defined, would you like init to add it for you?", gpa)) { |
| 78 | var realtext = text; | 79 | var realtext = text; |
| ... | @@ -134,7 +135,7 @@ pub fn execute(args: [][]u8) !void { | ... | @@ -134,7 +135,7 @@ pub fn execute(args: [][]u8) !void { |
| 134 | if (try u.does_folder_exist(".git")) { | 135 | if (try u.does_folder_exist(".git")) { |
| 135 | const do = try inquirer.forConfirm(stdout, stdin, "It appears you're using git. Do you want init to add Zigmod to your .gitignore?", gpa); | 136 | const do = try inquirer.forConfirm(stdout, stdin, "It appears you're using git. Do you want init to add Zigmod to your .gitignore?", gpa); |
| 136 | if (do) { | 137 | if (do) { |
| 137 | const exists = try u.does_file_exist(null, ".gitignore"); | 138 | const exists = try extras.doesFileExist(null, ".gitignore"); |
| 138 | const file: std.fs.File = try (if (exists) cwd.openFile(".gitignore", .{ .mode = .read_write }) else cwd.createFile(".gitignore", .{})); | 139 | const file: std.fs.File = try (if (exists) cwd.openFile(".gitignore", .{ .mode = .read_write }) else cwd.createFile(".gitignore", .{})); |
| 139 | defer file.close(); | 140 | defer file.close(); |
| 140 | const len = try file.getEndPos(); | 141 | const len = try file.getEndPos(); |
| ... | @@ -153,7 +154,7 @@ pub fn execute(args: [][]u8) !void { | ... | @@ -153,7 +154,7 @@ pub fn execute(args: [][]u8) !void { |
| 153 | if (try u.does_folder_exist(".git")) { | 154 | if (try u.does_folder_exist(".git")) { |
| 154 | const do = try inquirer.forConfirm(stdout, stdin, "It appears you're using git. Do you want init to add Zigmod to your .gitattributes?", gpa); | 155 | const do = try inquirer.forConfirm(stdout, stdin, "It appears you're using git. Do you want init to add Zigmod to your .gitattributes?", gpa); |
| 155 | if (do) { | 156 | if (do) { |
| 156 | const exists = try u.does_file_exist(null, ".gitattributes"); | 157 | const exists = try extras.doesFileExist(null, ".gitattributes"); |
| 157 | const file: std.fs.File = try (if (exists) cwd.openFile(".gitattributes", .{ .mode = .read_write }) else cwd.createFile(".gitattributes", .{})); | 158 | const file: std.fs.File = try (if (exists) cwd.openFile(".gitattributes", .{ .mode = .read_write }) else cwd.createFile(".gitattributes", .{})); |
| 158 | defer file.close(); | 159 | defer file.close(); |
| 159 | const len = try file.getEndPos(); | 160 | const len = try file.getEndPos(); |
| ... | @@ -188,7 +189,7 @@ pub fn writeLibManifest(w: std.fs.File.Writer, id: string, name: string, entry: | ... | @@ -188,7 +189,7 @@ pub fn writeLibManifest(w: std.fs.File.Writer, id: string, name: string, entry: |
| 188 | 189 | ||
| 189 | fn guessCopyrightName() !?string { | 190 | fn guessCopyrightName() !?string { |
| 190 | const home = (try knownfolders.open(gpa, .home, .{})).?; | 191 | const home = (try knownfolders.open(gpa, .home, .{})).?; |
| 191 | if (!(try u.does_file_exist(home, ".gitconfig"))) return null; | 192 | if (!(try extras.doesFileExist(home, ".gitconfig"))) return null; |
| 192 | const file = try home.openFile(".gitconfig", .{}); | 193 | const file = try home.openFile(".gitconfig", .{}); |
| 193 | const content = try file.reader().readAllAlloc(gpa, 1024 * 1024); | 194 | const content = try file.reader().readAllAlloc(gpa, 1024 * 1024); |
| 194 | var iniO = try ini.parseIntoMap(content, gpa); | 195 | var iniO = try ini.parseIntoMap(content, gpa); |
src/common.zig+1-1| ... | @@ -346,7 +346,7 @@ pub fn add_files_package(alloc: std.mem.Allocator, cachepath: string, pkg_name: | ... | @@ -346,7 +346,7 @@ pub fn add_files_package(alloc: std.mem.Allocator, cachepath: string, pkg_name: |
| 346 | pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]string { | 346 | pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]string { |
| 347 | var list = std.ArrayList([4]string).init(alloc); | 347 | var list = std.ArrayList([4]string).init(alloc); |
| 348 | const max = std.math.maxInt(usize); | 348 | const max = std.math.maxInt(usize); |
| 349 | if (!try u.does_file_exist(dir, "zigmod.lock")) return &[_][4]string{}; | 349 | if (!try extras.doesFileExist(dir, "zigmod.lock")) return &[_][4]string{}; |
| 350 | const f = try dir.openFile("zigmod.lock", .{}); | 350 | const f = try dir.openFile("zigmod.lock", .{}); |
| 351 | const r = f.reader(); | 351 | const r = f.reader(); |
| 352 | var i: usize = 0; | 352 | var i: usize = 0; |
src/util/funcs.zig+5-15| ... | @@ -45,16 +45,6 @@ pub fn split(alloc: std.mem.Allocator, in: string, delim: string) ![]string { | ... | @@ -45,16 +45,6 @@ pub fn split(alloc: std.mem.Allocator, in: string, delim: string) ![]string { |
| 45 | return list.toOwnedSlice(); | 45 | return list.toOwnedSlice(); |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | pub fn does_file_exist(dir: ?std.fs.Dir, fpath: string) !bool { | ||
| 49 | const file = (dir orelse std.fs.cwd()).openFile(fpath, .{}) catch |e| switch (e) { | ||
| 50 | error.FileNotFound => return false, | ||
| 51 | error.IsDir => return true, | ||
| 52 | else => return e, | ||
| 53 | }; | ||
| 54 | defer file.close(); | ||
| 55 | return true; | ||
| 56 | } | ||
| 57 | |||
| 58 | pub fn does_folder_exist(fpath: string) !bool { | 48 | pub fn does_folder_exist(fpath: string) !bool { |
| 59 | const file = std.fs.cwd().openFile(fpath, .{}) catch |e| switch (e) { | 49 | const file = std.fs.cwd().openFile(fpath, .{}) catch |e| switch (e) { |
| 60 | error.FileNotFound => return false, | 50 | error.FileNotFound => return false, |
| ... | @@ -243,7 +233,7 @@ pub fn detect_pkgname(alloc: std.mem.Allocator, override: string, dir: string) ! | ... | @@ -243,7 +233,7 @@ pub fn detect_pkgname(alloc: std.mem.Allocator, override: string, dir: string) ! |
| 243 | return override; | 233 | return override; |
| 244 | } | 234 | } |
| 245 | const dirO = if (dir.len == 0) std.fs.cwd() else try std.fs.cwd().openDir(dir, .{}); | 235 | const dirO = if (dir.len == 0) std.fs.cwd() else try std.fs.cwd().openDir(dir, .{}); |
| 246 | if (!(try does_file_exist(dirO, "build.zig"))) { | 236 | if (!(try extras.doesFileExist(dirO, "build.zig"))) { |
| 247 | return error.NoBuildZig; | 237 | return error.NoBuildZig; |
| 248 | } | 238 | } |
| 249 | const dpath = try std.fs.realpathAlloc(alloc, try std.fs.path.join(alloc, &.{ dir, "build.zig" })); | 239 | const dpath = try std.fs.realpathAlloc(alloc, try std.fs.path.join(alloc, &.{ dir, "build.zig" })); |
| ... | @@ -256,20 +246,20 @@ pub fn detect_pkgname(alloc: std.mem.Allocator, override: string, dir: string) ! | ... | @@ -256,20 +246,20 @@ pub fn detect_pkgname(alloc: std.mem.Allocator, override: string, dir: string) ! |
| 256 | 246 | ||
| 257 | pub fn detct_mainfile(alloc: std.mem.Allocator, override: string, dir: ?std.fs.Dir, name: string) !string { | 247 | pub fn detct_mainfile(alloc: std.mem.Allocator, override: string, dir: ?std.fs.Dir, name: string) !string { |
| 258 | if (override.len > 0) { | 248 | if (override.len > 0) { |
| 259 | if (try does_file_exist(dir, override)) { | 249 | if (try extras.doesFileExist(dir, override)) { |
| 260 | if (std.mem.endsWith(u8, override, ".zig")) { | 250 | if (std.mem.endsWith(u8, override, ".zig")) { |
| 261 | return override; | 251 | return override; |
| 262 | } | 252 | } |
| 263 | } | 253 | } |
| 264 | } | 254 | } |
| 265 | const namedotzig = try std.mem.concat(alloc, u8, &.{ name, ".zig" }); | 255 | const namedotzig = try std.mem.concat(alloc, u8, &.{ name, ".zig" }); |
| 266 | if (try does_file_exist(dir, namedotzig)) { | 256 | if (try extras.doesFileExist(dir, namedotzig)) { |
| 267 | return namedotzig; | 257 | return namedotzig; |
| 268 | } | 258 | } |
| 269 | if (try does_file_exist(dir, try std.fs.path.join(alloc, &.{ "src", "lib.zig" }))) { | 259 | if (try extras.doesFileExist(dir, try std.fs.path.join(alloc, &.{ "src", "lib.zig" }))) { |
| 270 | return "src/lib.zig"; | 260 | return "src/lib.zig"; |
| 271 | } | 261 | } |
| 272 | if (try does_file_exist(dir, try std.fs.path.join(alloc, &.{ "src", "main.zig" }))) { | 262 | if (try extras.doesFileExist(dir, try std.fs.path.join(alloc, &.{ "src", "main.zig" }))) { |
| 273 | return "src/main.zig"; | 263 | return "src/main.zig"; |
| 274 | } | 264 | } |
| 275 | return error.CantFindMain; | 265 | return error.CantFindMain; |