| author | |
| committer | |
| log | e8b3866c860562bccb483f7c51970776bfcb1d86 |
| tree | 8de65271531017d886c2cdc4bf189219096cf4cc |
| parent | 396f63375039cd6f42a22b7758864a810a8f32c8 |
4 files changed, 86 insertions(+), 0 deletions(-)
docs/commands/README.md+1| ... | @@ -17,3 +17,4 @@ Running `zigmod` with no commands will print this list. | ... | @@ -17,3 +17,4 @@ Running `zigmod` with no commands will print this list. |
| 17 | - [`aq`](aq.md) | 17 | - [`aq`](aq.md) |
| 18 | - [`aq add`](aq_add.md) | 18 | - [`aq add`](aq_add.md) |
| 19 | - [`aq showjson`](aq_showjson.md) | 19 | - [`aq showjson`](aq_showjson.md) |
| 20 | - [`aq install`](aq_install.md) |
docs/commands/aq_install.md created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | ## `aq install` command | ||
| 2 | ``` | ||
| 3 | zigmod aq install <package> | ||
| 4 | ``` | ||
| 5 | |||
| 6 | This command takes `<package>` and installs it for use on your local machine. | ||
| 7 | |||
| 8 | If you're on the details page for a package, the string this command is expecting is the path of the url after the domain name. So for example for the package https://aquila.red/1/nektro/discord-archiver, you would add it using `zigmod aq install 1/nektro/discord-archiver`. | ||
| 9 | |||
| 10 | Adding `~/.zigmod/bin` to your `$PATH` will allow you to reference the commands by name instead of by absolute path. | ||
| 11 | |||
| 12 | The directory `~/.cache/zigmod` is a cache directory and may be deleted at any time. | ||
src/cmd/aq.zig+2| ... | @@ -12,6 +12,7 @@ const u = @import("./../util/index.zig"); | ... | @@ -12,6 +12,7 @@ const u = @import("./../util/index.zig"); |
| 12 | pub const commands = struct { | 12 | pub const commands = struct { |
| 13 | pub const add = @import("./aquila/add.zig"); | 13 | pub const add = @import("./aquila/add.zig"); |
| 14 | pub const showjson = @import("./aquila/showjson.zig"); | 14 | pub const showjson = @import("./aquila/showjson.zig"); |
| 15 | pub const install = @import("./aquila/install.zig"); | ||
| 15 | }; | 16 | }; |
| 16 | 17 | ||
| 17 | pub const server_root = "https://aquila.red"; | 18 | pub const server_root = "https://aquila.red"; |
| ... | @@ -26,6 +27,7 @@ pub fn execute(args: [][]u8) !void { | ... | @@ -26,6 +27,7 @@ pub fn execute(args: [][]u8) !void { |
| 26 | \\The subcommands available are: | 27 | \\The subcommands available are: |
| 27 | \\ - add Append this package to your dependencies | 28 | \\ - add Append this package to your dependencies |
| 28 | \\ - showjson Print debug api data to stdout | 29 | \\ - showjson Print debug api data to stdout |
| 30 | \\ - install Install a package | ||
| 29 | }); | 31 | }); |
| 30 | return; | 32 | return; |
| 31 | } | 33 | } |
src/cmd/aquila/install.zig created+71| ... | @@ -0,0 +1,71 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const gpa = std.heap.c_allocator; | ||
| 3 | |||
| 4 | const knownfolders = @import("known-folders"); | ||
| 5 | |||
| 6 | const u = @import("./../../util/index.zig"); | ||
| 7 | const common = @import("./../../common.zig"); | ||
| 8 | |||
| 9 | pub fn execute(args: [][]u8) !void { | ||
| 10 | const home = try knownfolders.getPath(gpa, .home); | ||
| 11 | const homepath = home.?; | ||
| 12 | const homedir = try std.fs.cwd().openDir(homepath, .{}); | ||
| 13 | |||
| 14 | if (!(try u.does_file_exist("zig.mod", homedir))) { | ||
| 15 | const f = try homedir.createFile("zig.mod", .{}); | ||
| 16 | defer f.close(); | ||
| 17 | const w = f.writer(); | ||
| 18 | const init = @import("../init.zig"); | ||
| 19 | try init.writeExeManifest(w, try u.random_string(48), "zigmod_installation", null, null); | ||
| 20 | } | ||
| 21 | |||
| 22 | // add to ~/zig.mod for later | ||
| 23 | const aqadd = @import("./add.zig"); | ||
| 24 | const pkgurl = aqadd.do(homedir, args[0]) catch |err| switch (err) { | ||
| 25 | error.AquilaBadResponse => return, | ||
| 26 | else => return err, | ||
| 27 | }; | ||
| 28 | |||
| 29 | // get modfile and dep | ||
| 30 | const m = try u.ModFile.from_dir(gpa, homedir); | ||
| 31 | var dep: u.Dep = undefined; | ||
| 32 | for (m.devdeps) |d| { | ||
| 33 | if (std.mem.eql(u8, d.path, pkgurl)) { | ||
| 34 | dep = d; | ||
| 35 | break; | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | // | ||
| 40 | const cache = try knownfolders.getPath(gpa, .cache); | ||
| 41 | const cachepath = try std.fs.path.join(gpa, &.{ cache.?, "zigmod", "deps" }); | ||
| 42 | |||
| 43 | // fetch singular pkg | ||
| 44 | var fetchoptions = common.CollectOptions{ | ||
| 45 | .log = true, | ||
| 46 | .update = false, | ||
| 47 | }; | ||
| 48 | try fetchoptions.init(); | ||
| 49 | const modpath = try common.get_modpath(cachepath, dep, "install", &fetchoptions); | ||
| 50 | const moddir = try std.fs.cwd().openDir(modpath, .{}); | ||
| 51 | |||
| 52 | // zigmod ci | ||
| 53 | const ci = @import("../ci.zig"); | ||
| 54 | try ci.do(modpath, moddir); | ||
| 55 | |||
| 56 | // zig build | ||
| 57 | const argv: []const []const u8 = &.{ | ||
| 58 | "zig", "build", | ||
| 59 | "--prefix", try std.fs.path.join(gpa, &.{ homepath, ".zigmod" }), | ||
| 60 | "--cache-dir", try std.fs.path.join(gpa, &.{ cache.?, "zigmod", "zig" }), | ||
| 61 | }; | ||
| 62 | const proc = try std.ChildProcess.init(argv, gpa); | ||
| 63 | proc.cwd = modpath; | ||
| 64 | const term = try proc.spawnAndWait(); | ||
| 65 | switch (term) { | ||
| 66 | .Exited => |v| u.assert(v == 0, "zig build failed with exit code: {d}", .{v}), | ||
| 67 | .Signal => |v| std.log.info("zig build was stopped with signal: {d}", .{v}), | ||
| 68 | .Stopped => |v| std.log.info("zig build was stopped with code: {d}", .{v}), | ||
| 69 | .Unknown => |v| std.log.info("zig build encountered unknown: {d}", .{v}), | ||
| 70 | } | ||
| 71 | } | ||