Something went wrong. Try again.
A Microsoft 365 mail client library for Zig, over Microsoft Graph
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
//! A command line client for the library: signs in, and then reads a real//! mailbox with what it got.//!//! It exists to be run by hand against something the test suite cannot reach.//! Everything in `tests/` talks to a Microsoft Graph written a few hundred//! lines away, so it proves the two halves agree with each other; only this//! proves the library agrees with Microsoft.//!//! ```console//! $ zig build run -- login --client-id <the application id> \//! --tenant common --store ~/.cache/zig-o365/tokens.json//! $ zig build run -- whoami --client-id ... --store ...//! $ zig build run -- folders --client-id ... --store ...//! $ zig build run -- messages --folder inbox --limit 20 --client-id ... --store ...//! $ zig build run -- get <id> --client-id ... --store ...//! $ zig build run -- mime <id> --client-id ... --store ... > message.eml//! $ zig build run -- delta --folder inbox --client-id ... --store ...//! ```//!//! Every command but `login` needs `--client-id` as well as `--store`, because//! refreshing an access token is a request made as the application and the//! application id is not in the store.//!//! `--client-secret` is for a confidential client. A desktop application should//! be registered as a *public* client and leave it off: it cannot keep a//! secret, and PKCE is what protects the flow instead.//!//! The store holds a refresh token, so it is written 0600 and belongs somewhere//! that stays that way.
const std = @import("std");const o365 = @import("o365");const oidc = @import("oidc");
const user_agent = "zig-o365/" ++ @import("build_options").version;
const usage = \\usage: zig-o365 <command> [options] \\ \\Commands: \\ login Sign in with a browser and store the tokens \\ whoami Print the mailbox this token belongs to \\ folders List every folder, with its path \\ messages List messages in a folder \\ get ID Fetch one message as JSON-ish fields \\ mime ID Fetch one message as RFC 5322, on stdout \\ attachments ID List the attachments of a message \\ fetch Fetch a folder's messages in $batch round trips \\ delta List what has changed in a folder since --token \\ \\Options: \\ --client-id ID Required by every command \\ --client-secret S Only for a confidential client; a desktop app \\ should be registered public and omit this \\ --tenant T common (default), organizations, consumers, a \\ tenant GUID, or a verified domain \\ --store PATH Where the tokens are kept (default \\ $XDG_CACHE_HOME/zig-o365/tokens.json) \\ --scope S Repeatable. Defaults to openid, offline_access, \\ User.Read and Mail.Read \\ --user ADDRESS The mailbox. Default "me" \\ \\login: \\ --login-hint S Which account to offer \\ --port N Fix the loopback port \\ --timeout SECONDS How long to wait for the browser (default 300) \\ \\messages, delta: \\ --folder F A folder id or a well-known name (default inbox; \\ "all" for every folder in the mailbox) \\ --limit N Stop after N messages (default 25, 0 for all) \\ \\messages: \\ --since ISO8601 Only messages received at or after this \\ --search TERM A $search term (cannot be used with --since) \\ \\delta: \\ --token LINK The deltaLink stored from a previous run \\;
const Command = enum { login, whoami, folders, messages, get, mime, attachments, fetch, delta,};
const Options = struct { command: Command = .whoami, positional: ?[]const u8 = null, client_id: ?[]const u8 = null, client_secret: ?[]const u8 = null, tenant: []const u8 = "common", store: ?[]const u8 = null, scopes: std.ArrayList([]const u8) = .empty, user: []const u8 = "me",
login_hint: ?[]const u8 = null, port: u16 = 0, timeout_s: u32 = 300,
folder: []const u8 = "inbox", limit: usize = 25, since: ?[]const u8 = null, search: ?[]const u8 = null, token: ?[]const u8 = null,};
pub fn main(init: std.process.Init) !void { const io = init.io; const gpa = init.gpa;
var stdout_buffer: [64 * 1024]u8 = undefined; var stdout_writer = std.Io.File.stdout().writer(io, &stdout_buffer); const out = &stdout_writer.interface; defer out.flush() catch {};
var options: Options = .{}; defer options.scopes.deinit(gpa);
var args: std.process.Args.Iterator = .init(init.minimal.args); _ = args.skip();
const command = args.next() orelse return fail(out, usage, .{}); options.command = std.meta.stringToEnum(Command, command) orelse return fail(out, "{s}\nno command called {s}\n", .{ usage, command });
while (args.next()) |arg| { if (std.mem.eql(u8, arg, "--client-id")) { options.client_id = args.next(); } else if (std.mem.eql(u8, arg, "--client-secret")) { options.client_secret = args.next(); } else if (std.mem.eql(u8, arg, "--tenant")) { options.tenant = args.next() orelse "common"; } else if (std.mem.eql(u8, arg, "--store")) { options.store = args.next(); } else if (std.mem.eql(u8, arg, "--scope")) { try options.scopes.append(gpa, args.next() orelse return fail(out, usage, .{})); } else if (std.mem.eql(u8, arg, "--user")) { options.user = args.next() orelse "me"; } else if (std.mem.eql(u8, arg, "--login-hint")) { options.login_hint = args.next(); } else if (std.mem.eql(u8, arg, "--port")) { options.port = std.fmt.parseInt(u16, args.next() orelse "0", 10) catch 0; } else if (std.mem.eql(u8, arg, "--timeout")) { options.timeout_s = std.fmt.parseInt(u32, args.next() orelse "300", 10) catch 300; } else if (std.mem.eql(u8, arg, "--folder")) { options.folder = args.next() orelse "inbox"; } else if (std.mem.eql(u8, arg, "--limit")) { options.limit = std.fmt.parseInt(usize, args.next() orelse "25", 10) catch 25; } else if (std.mem.eql(u8, arg, "--since")) { options.since = args.next(); } else if (std.mem.eql(u8, arg, "--search")) { options.search = args.next(); } else if (std.mem.eql(u8, arg, "--token")) { options.token = args.next(); } else if (std.mem.startsWith(u8, arg, "-")) { return fail(out, "{s}\nno option called {s}\n", .{ usage, arg }); } else if (options.positional == null) { options.positional = arg; } else { return fail(out, "{s}\ntoo many arguments\n", .{usage}); } }
const client_id = options.client_id orelse return fail(out, "--client-id is required\n", .{});
var tenant = o365.tenant.init(gpa, options.tenant, .{}) catch |err| switch (err) { error.InvalidTenant => return fail( out, "{s} is not a tenant: use common, organizations, consumers, a GUID, or a domain\n", .{options.tenant}, ), else => |e| return e, }; defer tenant.deinit();
const store_path = try resolveStorePath(gpa, init.environ_map, &options); defer gpa.free(store_path);
// The directory is opened rather than the path being carried around, // because that is what `TokenStore` wants: it is told where, not asked to // work it out. const dirname = std.fs.path.dirname(store_path) orelse "."; var dir = std.Io.Dir.cwd().createDirPathOpen(io, dirname, .{}) catch return fail(out, "cannot open {s}\n", .{dirname}); defer dir.close(io);
var store: o365.TokenStore = .{ .dir = dir, .path = std.fs.path.basename(store_path), .io = io, };
const scopes: []const []const u8 = if (options.scopes.items.len > 0) options.scopes.items else o365.scopes.mirror;
if (options.command == .login) { return login(io, gpa, out, &options, &store, &tenant, client_id, scopes); }
var tokens = store.load(gpa) catch |err| switch (err) { error.NoStoredTokens => return fail( out, "no tokens in {s}; run `login` first\n", .{store_path}, ), error.Malformed => return fail(out, "{s} is not a token file\n", .{store_path}), else => |e| return e, }; defer tokens.deinit();
var client: o365.Client = .{ .gpa = gpa, .oauth = .{ .provider = tenant.provider, .client_id = client_id, .client_secret = options.client_secret, .redirect_uri = "http://localhost/callback", .scopes = scopes, .user_agent = user_agent, }, .tokens = &tokens, .user_id = options.user, .user_agent = user_agent, .on_refresh = store.refreshHook(), };
var d: o365.Client.Diagnostics = .init(client.gpa); defer d.deinit();
switch (options.command) { .login => unreachable, .whoami => try showUser(io, gpa, out, &client, &d), .folders => try showFolders(io, gpa, out, &client, &d), .messages => try showMessages(io, gpa, out, &client, &options, &d), .get => try showMessage(io, gpa, out, &client, &options, &d), .mime => try showMime(io, gpa, out, &client, &options, &d), .attachments => try showAttachments(io, gpa, out, &client, &options, &d), .fetch => try fetchBatched(io, gpa, out, &client, &options, &d), .delta => try showDelta(io, gpa, out, &client, &options, &d), }}
fn login( io: std.Io, gpa: std.mem.Allocator, out: *std.Io.Writer, options: *const Options, store: *o365.TokenStore, tenant: *const o365.tenant.Tenant, client_id: []const u8, scopes: []const []const u8,) !void { // The listener comes first: the redirect URI has the port in it, and the // port is not known until the socket is bound. var listener = try oidc.loopback.Listener.listen(io, .{ .port = options.port }); defer listener.deinit(io);
const redirect_uri = try listener.redirectUri(gpa); defer gpa.free(redirect_uri);
const client: oidc.Client = .{ .provider = tenant.provider, .client_id = client_id, .client_secret = options.client_secret, .redirect_uri = redirect_uri, .scopes = scopes, .user_agent = user_agent, };
if (!o365.scopes.granted(scopes, o365.scopes.offline_access)) { try out.writeAll( \\warning: offline_access is not among the scopes asked for, so no \\refresh token will come back and this will stop working in about \\an hour. It is the Microsoft equivalent of Google's \\access_type=offline, and it has to be requested explicitly. \\ \\ ); }
const rng_source: std.Random.IoSource = .{ .io = io }; var authorization = try client.authorize(gpa, rng_source.interface(), .{ .login_hint = options.login_hint, }); defer authorization.deinit();
try out.print( \\Open this in a browser: \\ \\ {s} \\ \\Listening on {s} \\ , .{ authorization.url, redirect_uri }); try out.flush();
var redirect = listener.wait(io, gpa, .{ .timeout = .{ .duration = .{ .raw = .fromSeconds(options.timeout_s), .clock = .awake, } }, }) catch |err| switch (err) { error.Timeout => return fail( out, "nobody came back within {d} seconds\n", .{options.timeout_s}, ), else => |e| return e, }; defer redirect.deinit();
var d: oidc.Client.Diagnostics = .{}; defer d.deinit(gpa);
var tokens = client.exchange(io, gpa, &authorization, redirect.query, &d) catch |err| { if (d.message()) |m| { try out.print("sign-in failed: {t}: {f}\n", .{ err, m }); } else { try out.print("sign-in failed: {t}\n", .{err}); } try out.flush(); std.process.exit(1); }; defer tokens.deinit();
if (tokens.refresh_token == null) { try out.writeAll( \\warning: no refresh token came back, so this will stop working in \\about an hour. offline_access is what asks for one. \\ ); }
try store.save(&tokens); try out.print("signed in; tokens written to {s}\n", .{store.path});
// What was *granted*, which is not always what was asked for: an // administrator may consent to less, and finding that out here is better // than finding it out as a 403 forty thousand messages into a walk. for (tokens.scopes) |s| try out.print(" scope {s}\n", .{s}); for ([_][]const u8{ o365.scopes.mail_read, o365.scopes.user_read }) |wanted| { if (!o365.scopes.granted(tokens.scopes, wanted)) { try out.print("note: {s} was not granted\n", .{o365.scopes.bare(wanted)}); } }}
fn showUser( io: std.Io, gpa: std.mem.Allocator, out: *std.Io.Writer, client: *o365.Client, d: *o365.Client.Diagnostics,) !void { var user = client.getUser(io, gpa, d) catch |err| return report(out, err, d); defer user.deinit();
const u = user.value; try out.print("id {s}\n", .{u.id}); try out.print("name {s}\n", .{u.display_name orelse "-"}); try out.print("mail {s}\n", .{u.mail orelse "-"}); try out.print("upn {s}\n", .{u.user_principal_name orelse "-"});}
fn showFolders( io: std.Io, gpa: std.mem.Allocator, out: *std.Io.Writer, client: *o365.Client, d: *o365.Client.Diagnostics,) !void { var tree = client.folderTree(io, gpa, .{}, d) catch |err| return report(out, err, d); defer tree.deinit();
for (tree.folders) |folder| { try out.print("{s:<8} {s:<8} {s}\n", .{ countOrDash(folder.total_item_count), countOrDash(folder.unread_item_count), folder.path, }); } try out.print("\n{d} folders\n", .{tree.count()});}
var count_buf: [16]u8 = undefined;
fn countOrDash(value: ?u32) []const u8 { const v = value orelse return "-"; return std.fmt.bufPrint(&count_buf, "{d}", .{v}) catch "-";}
fn showMessages( io: std.Io, gpa: std.mem.Allocator, out: *std.Io.Writer, client: *o365.Client, options: *const Options, d: *o365.Client.Diagnostics,) !void { var filter: ?[]u8 = null; defer if (filter) |f| gpa.free(f); if (options.since) |since| { const when = o365.iso8601.parse(since) orelse return fail( out, "--since wants an ISO 8601 instant such as 2024-01-01T00:00:00Z, not {s}\n", .{since}, ); filter = try o365.Client.receivedAfter(gpa, when); }
// Graph refuses a request carrying both, with a 400 rather than a slow // answer, so it is worth saying so here rather than passing it on. if (filter != null and options.search != null) { return fail(out, "--since and --search cannot be used together\n", .{}); }
var it = try client.messageIterator(gpa, .{ .folder = if (std.mem.eql(u8, options.folder, "all")) null else options.folder, .select = o365.Client.walk_select, .filter = filter, .search = options.search, // Not with `$search`, which Graph will not order. .order_by = if (options.search == null) "receivedDateTime desc" else null, }); defer it.deinit();
var count: usize = 0; while (true) { // Parenthesised: `catch` binds tighter than `orelse`, so without // them the `orelse` would attach to the `catch` expression and // `message` would still be an optional. const message = (it.next(io, d) catch |err| return report(out, err, d)) orelse break; if (options.limit != 0 and count >= options.limit) break; count += 1;
var when: [32]u8 = undefined; try out.print("{s} {s:<20} {s}\n", .{ if (message.timestamp()) |t| o365.iso8601.bufRender(&when, t) else "-", message.fromAddress() orelse "-", message.subject orelse "(no subject)", }); try out.print(" {s}\n", .{message.id}); }
try out.print("\n{d} messages\n", .{count}); if (it.next_url != null) { try out.writeAll("more; raise --limit to see them\n"); }}
fn showMessage( io: std.Io, gpa: std.mem.Allocator, out: *std.Io.Writer, client: *o365.Client, options: *const Options, d: *o365.Client.Diagnostics,) !void { const id = options.positional orelse return fail(out, "`get` wants a message id\n", .{});
var message = client.getMessage(io, gpa, id, .{ .body_type = .text, }, d) catch |err| return report(out, err, d); defer message.deinit();
const m = message.value; var when: [32]u8 = undefined;
try out.print("id {s}\n", .{m.id}); try out.print("folder {s}\n", .{m.parent_folder_id orelse "-"}); // The one that survives the message being moved, and so the one a local // store should key on. try out.print("messageid {s}\n", .{m.internet_message_id orelse "-"}); try out.print("received {s}\n", .{ if (m.received_date_time) |t| o365.iso8601.bufRender(&when, t) else "-", }); try out.print("from {s}\n", .{m.fromAddress() orelse "-"}); try out.writeAll("to "); for (m.to_recipients, 0..) |r, i| { try out.print("{s}{s}", .{ if (i == 0) "" else ", ", r.address orelse "-" }); } try out.writeAll("\n"); try out.print("subject {s}\n", .{m.subject orelse "-"}); try out.print("read {?}\n", .{m.is_read}); try out.print("attach {?}\n", .{m.has_attachments}); if (m.categories.len > 0) { try out.writeAll("category "); for (m.categories, 0..) |c, i| { try out.print("{s}{s}", .{ if (i == 0) "" else " ", c }); } try out.writeAll("\n"); }
if (m.body) |body| { try out.print("\n-- body ({t}) --\n", .{body.content_type}); try out.print("{s}\n", .{body.content orelse ""}); }}
fn showMime( io: std.Io, gpa: std.mem.Allocator, out: *std.Io.Writer, client: *o365.Client, options: *const Options, d: *o365.Client.Diagnostics,) !void { const id = options.positional orelse return fail(out, "`mime` wants a message id\n", .{});
const mime = client.getMime(io, gpa, id, d) catch |err| return report(out, err, d); defer gpa.free(mime);
// The whole message and nothing else, so that the output can be redirected // into a file that is a valid RFC 5322 message. try out.writeAll(mime);}
fn showAttachments( io: std.Io, gpa: std.mem.Allocator, out: *std.Io.Writer, client: *o365.Client, options: *const Options, d: *o365.Client.Diagnostics,) !void { const id = options.positional orelse return fail(out, "`attachments` wants a message id\n", .{});
var page = client.listAttachments(io, gpa, id, .{}, d) catch |err| return report(out, err, d); defer page.deinit();
var name_buf: [256]u8 = undefined; for (page.items) |attachment| { try out.print("{s:<12} {s:<10} {s:<32} {s}\n", .{ @tagName(attachment.kind), countOrDash(attachment.size), attachment.safeName(&name_buf), attachment.content_type orelse "-", }); } try out.print("\n{d} attachments\n", .{page.items.len});}
/// The two halves of a mailbox walk, with the second one batched: list the ids,/// then fetch them twenty at a time.////// This is what `$batch` is for, and running it against a real mailbox is the/// only way to find out whether the round-trip count is what this claims --/// which is why it is a command rather than only a test.fn fetchBatched( io: std.Io, gpa: std.mem.Allocator, out: *std.Io.Writer, client: *o365.Client, options: *const Options, d: *o365.Client.Diagnostics,) !void { var ids: std.ArrayList([]u8) = .empty; defer { for (ids.items) |id| gpa.free(id); ids.deinit(gpa); }
{ var it = try client.messageIterator(gpa, .{ .folder = if (std.mem.eql(u8, options.folder, "all")) null else options.folder, // Only the id is needed here: the batch fetches the rest. .select = &.{"id"}, }); defer it.deinit();
while (true) { const stub = (it.next(io, d) catch |err| return report(out, err, d)) orelse break; if (options.limit != 0 and ids.items.len >= options.limit) break; // Copied, because the next call frees the page it came from. try ids.append(gpa, try gpa.dupe(u8, stub.id)); } }
if (ids.items.len == 0) { try out.writeAll("no messages\n"); return; }
var fetched = client.getMessages( io, gpa, ids.items, .{ .select = o365.Client.walk_select }, d, ) catch |err| return report(out, err, d); defer fetched.deinit();
for (fetched.items) |item| { const message = item.message orelse { // A message deleted between the listing and the fetch, which a // walk has to survive rather than stop on. try out.print("{d:>3} (not fetched)\n", .{@intFromEnum(item.status)}); continue; }; var when: [32]u8 = undefined; try out.print("{s} {s:<28} {s}\n", .{ if (message.timestamp()) |t| o365.iso8601.bufRender(&when, t) else "-", message.fromAddress() orelse "-", message.subject orelse "(no subject)", }); }
try out.print( "\n{d} of {d} fetched in {d} round trip{s}\n", .{ fetched.okCount(), fetched.items.len, fetched.round_trips, if (fetched.round_trips == 1) "" else "s", }, );}
fn showDelta( io: std.Io, gpa: std.mem.Allocator, out: *std.Io.Writer, client: *o365.Client, options: *const Options, d: *o365.Client.Diagnostics,) !void { if (std.mem.eql(u8, options.folder, "all")) { return fail( out, \\a delta query is per folder: Graph has no mailbox-wide change feed, \\so name one folder and keep one token for each. \\ , .{}, ); }
var it = client.messageDelta(gpa, .{ .folder = options.folder, .delta_link = options.token, .select = o365.Client.walk_select, }) catch |err| switch (err) { error.UntrustedLink => return fail( out, "that --token points at another host and was not followed\n", .{}, ), else => |e| return e, }; defer it.deinit();
var changed: usize = 0; var removed: usize = 0; while (true) { const message = (it.next(io, d) catch |err| switch (err) { // The one failure worth explaining rather than printing: it means // the incremental path is gone, not that anything is broken. error.ResyncRequired => return fail( out, \\that delta token has aged out. There is no incremental update \\from here -- run `delta` again with no --token, which walks the \\folder in full and hands back a fresh one. \\ , .{}, ), else => |e| return report(out, e, d), }) orelse break;
if (options.limit != 0 and changed + removed >= options.limit) break;
if (message.isRemoved()) { removed += 1; try out.print("removed {s}\n", .{message.id}); } else { changed += 1; var when: [32]u8 = undefined; try out.print("changed {s} {s}\n", .{ if (message.timestamp()) |t| o365.iso8601.bufRender(&when, t) else "-", message.subject orelse "(no subject)", }); } }
try out.print("\n{d} changed, {d} removed\n", .{ changed, removed }); if (it.delta_link) |link| { // What an application would store to resume. Printed because the whole // point of exposing it is that the library does not store it. try out.print("next time, --token '{s}'\n", .{link}); } else { try out.writeAll( \\the walk did not reach the end, so there is no token to resume \\from: Graph only issues one on the last page. \\ ); }}
/// `--store`, or `$XDG_CACHE_HOME/zig-o365/tokens.json`, or/// `$HOME/.cache/...`. Owned by the caller.fn resolveStorePath( gpa: std.mem.Allocator, env: *const std.process.Environ.Map, options: *const Options,) ![]u8 { if (options.store) |p| return gpa.dupe(u8, p);
if (env.get("XDG_CACHE_HOME")) |cache| { if (cache.len > 0) { return std.fs.path.join(gpa, &.{ cache, "zig-o365", "tokens.json" }); } } const home = env.get("HOME") orelse return error.NoHomeDirectory; return std.fs.path.join(gpa, &.{ home, ".cache", "zig-o365", "tokens.json" });}
/// Says what went wrong with as much as the diagnostics know, then stops.////// The distinction worth keeping is between a failure the user can do/// something about -- the grant is gone, the scope is too narrow -- and one/// they cannot, and the API error object is what draws it.fn report(out: *std.Io.Writer, err: anyerror, d: *const o365.Client.Diagnostics) noreturn { out.print("{t}: {f}\n", .{ err, d }) catch {}; switch (err) { error.Unauthorized, error.RefreshFailed => out.writeAll( "the grant is no longer good; run `login` again\n", ) catch {}, error.NoRefreshToken => out.writeAll( "there is no refresh token stored; run `login` again with offline_access\n", ) catch {}, error.TooManyRetries => out.writeAll( "Graph kept asking for a slower pace; try again later\n", ) catch {}, error.UntrustedLink => out.writeAll( "a continuation link pointed at another host and was not followed\n", ) catch {}, else => {}, } if (d.apiError()) |api| { if (api.isPermissionFailure(d.http.status orelse .ok)) { out.writeAll( "the stored token's permissions do not cover this; sign in " ++ "again with the --scope this needs, and note that a tenant " ++ "administrator may have to consent to it\n", ) catch {}; } } if (d.requestId()) |id| { out.print("quote request-id {s} in a support request\n", .{id}) catch {}; } out.flush() catch {}; std.process.exit(1);}
fn fail(out: *std.Io.Writer, comptime fmt: []const u8, args: anytype) noreturn { out.print(fmt, args) catch {}; out.flush() catch {}; std.process.exit(1);}
test { // The CLI has no tests of its own; this is here so that `zig build test` // compiles it, which is what catches it having drifted from the library. std.testing.refAllDecls(@This());}