authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-05-07 03:42:25 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-05-07 03:42:25 -07:00
log70bb35dc54fb157da9576e9d919f544ac9d4405c
tree7591d88f72bced49c5f6536fe5fdabb286cb3dae
parent29460c33bd91ab7169f9edeb789f9009ffe56e87

cmd/fetch: add --no-update flag


2 files changed, 7 insertions(+), 6 deletions(-)

src/cmd/fetch.zig+3-2
...@@ -12,10 +12,11 @@ const common = @import("./../common.zig");...@@ -12,10 +12,11 @@ const common = @import("./../common.zig");
12pub fn execute(args: [][]u8) !void {12pub fn execute(args: [][]u8) !void {
13 //13 //
14 const dir = try fs.path.join(gpa, &.{ ".zigmod", "deps" });14 const dir = try fs.path.join(gpa, &.{ ".zigmod", "deps" });
15 const should_update = !(args.len >= 1 and std.mem.eql(u8, args[0], "--no-update"));
1516
16 const top_module = try common.collect_deps_deep(dir, "zig.mod", .{17 const top_module = try common.collect_deps_deep(dir, "zig.mod", .{
17 .log = true,18 .log = should_update,
18 .update = true,19 .update = should_update,
19 });20 });
2021
21 //22 //
src/common.zig+4-4
...@@ -12,7 +12,7 @@ pub const CollectOptions = struct {...@@ -12,7 +12,7 @@ pub const CollectOptions = struct {
12 update: bool,12 update: bool,
13};13};
1414
15pub fn collect_deps_deep(dir: []const u8, mpath: []const u8, comptime options: CollectOptions) !u.Module {15pub fn collect_deps_deep(dir: []const u8, mpath: []const u8, options: CollectOptions) !u.Module {
16 const m = try u.ModFile.init(gpa, mpath);16 const m = try u.ModFile.init(gpa, mpath);
17 const moduledeps = &std.ArrayList(u.Module).init(gpa);17 const moduledeps = &std.ArrayList(u.Module).init(gpa);
18 try moduledeps.append(try collect_deps(dir, mpath, options));18 try moduledeps.append(try collect_deps(dir, mpath, options));
...@@ -35,7 +35,7 @@ pub fn collect_deps_deep(dir: []const u8, mpath: []const u8, comptime options: C...@@ -35,7 +35,7 @@ pub fn collect_deps_deep(dir: []const u8, mpath: []const u8, comptime options: C
35 };35 };
36}36}
3737
38pub fn collect_deps(dir: []const u8, mpath: []const u8, comptime options: CollectOptions) anyerror!u.Module {38pub fn collect_deps(dir: []const u8, mpath: []const u8, options: CollectOptions) anyerror!u.Module {
39 const m = try u.ModFile.init(gpa, mpath);39 const m = try u.ModFile.init(gpa, mpath);
40 const moduledeps = &std.ArrayList(u.Module).init(gpa);40 const moduledeps = &std.ArrayList(u.Module).init(gpa);
41 for (m.deps) |d| {41 for (m.deps) |d| {
...@@ -67,7 +67,7 @@ pub fn collect_pkgs(mod: u.Module, list: *std.ArrayList(u.Module)) anyerror!void...@@ -67,7 +67,7 @@ pub fn collect_pkgs(mod: u.Module, list: *std.ArrayList(u.Module)) anyerror!void
67 }67 }
68}68}
6969
70fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, comptime options: CollectOptions) ![]const u8 {70fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, options: CollectOptions) ![]const u8 {
71 const p = try fs.path.join(gpa, &.{ basedir, try d.clean_path() });71 const p = try fs.path.join(gpa, &.{ basedir, try d.clean_path() });
72 const pv = try fs.path.join(gpa, &.{ basedir, try d.clean_path_v() });72 const pv = try fs.path.join(gpa, &.{ basedir, try d.clean_path_v() });
73 const tempdir = try fs.path.join(gpa, &.{ basedir, "temp" });73 const tempdir = try fs.path.join(gpa, &.{ basedir, "temp" });
...@@ -159,7 +159,7 @@ fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, comptime o...@@ -159,7 +159,7 @@ fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, comptime o
159 }159 }
160}160}
161161
162fn get_module_from_dep(list: *std.ArrayList(u.Module), d: u.Dep, dir: []const u8, parent_name: []const u8, comptime options: CollectOptions) !void {162fn get_module_from_dep(list: *std.ArrayList(u.Module), d: u.Dep, dir: []const u8, parent_name: []const u8, options: CollectOptions) !void {
163 const moddir = try get_moddir(dir, d, parent_name, options);163 const moddir = try get_moddir(dir, d, parent_name, options);
164 switch (d.type) {164 switch (d.type) {
165 .system_lib => {165 .system_lib => {