const std = @import("std");

/// Shared per-process context threaded through CLI commands via
/// `zli`'s `CommandContext.data`. Carries the working `Io` and
/// `Environ.Map` provided by `std.process.Init` in `main`.
///
/// The single-threaded global `Io` (`std.Io.Threaded.global_single_threaded`)
/// has a `failing` allocator and cannot be used for any operation that
/// allocates (e.g. `std.process.spawn`). Commands must use this context's
/// `io` instead.
pub const AppContext = struct {
    io: std.Io,
    environ_map: *std.process.Environ.Map,

    pub fn from(ctx: anytype) *AppContext {
        return @ptrCast(@alignCast(ctx.data.?));
    }
};
