A SpaceTraders Agent

simple main querying ships

altagos.dev 2a9a563f 961129c8

verified
+62 -3
-1
build.zig
··· 66 66 run_step.dependOn(&run_cmd.step); 67 67 68 68 const test_step = b.step("test", "Run tests"); 69 - 70 69 addTest(b, test_step, "meta tests", meta); 71 70 addTest(b, test_step, "st tests", st); 72 71 addTest(b, test_step, "agent tests", agent);
+62 -2
src/main.zig
··· 1 1 const std = @import("std"); 2 2 3 - pub fn main() void { 4 - std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); 3 + const pretty = @import("meta").pretty; 4 + 5 + const meta = @import("meta"); 6 + 7 + const st = @import("st"); 8 + const m = st.models; 9 + const Client = st.http.Client; 10 + const RawResponse = st.http.RawResponse; 11 + const Response = st.http.Response; 12 + 13 + const Info = st.models.Info; 14 + const agents = st.models.agents; 15 + 16 + const agent = @import("agent"); 17 + const Config = agent.config.Config; 18 + 19 + pub const known_folders_config: @import("known-folders").KnownFolderConfig = .{ 20 + .xdg_on_mac = true, 21 + }; 22 + 23 + fn juicyMain( 24 + gpa: std.mem.Allocator, 25 + io: std.Io, 26 + config: *const Config, 27 + client: *Client, 28 + ) !void { 29 + _ = gpa; 30 + _ = config; 31 + // _ = io; 32 + // _ = client; 33 + 34 + var fleet_f = try st.fleet.listShips(client, .{}); 35 + defer _ = fleet_f.cancel(io) catch {}; 36 + 37 + const fleet = try fleet_f.await(io); 38 + defer fleet.deinit(); 39 + 40 + std.log.info("{f}", .{pretty(fleet.value)}); 41 + } 42 + 43 + pub fn main() !void { 44 + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; 45 + defer _ = gpa.deinit(); 46 + const allocator = gpa.allocator(); 47 + 48 + var io_impl: std.Io.Threaded = .init(allocator); 49 + defer io_impl.deinit(); 50 + const io = io_impl.io(); 51 + 52 + std.log.debug("Io threads: {}", .{try io_impl.cpu_count}); 53 + 54 + const config = try agent.config.load(io, allocator); 55 + defer agent.config.free(allocator, config); 56 + 57 + var client = Client.init(allocator, io, .{ 58 + .auth = config.auth, 59 + // .base_url = "http://localhost:4000/test", 60 + // .base_url = "https://api.staging.spacetraders.io/v2", 61 + }); 62 + defer client.deinit(); 63 + 64 + try juicyMain(allocator, io, &config, &client); 5 65 }