Skip to content
1        10        20        30        40        50        60        70        80        90        1001//! `any` installs the silen-infra skill into the repository it is run in.2const std = @import("std");3const build_options = @import("build_options");4const cli = @import("cli.zig");5const install = @import("install.zig");6const skill = @import("skill.zig");78pub fn main(init: std.process.Init) !void {9    const arena = init.arena.allocator();10    const args = try init.minimal.args.toSlice(arena);11    run(arena, init.io, args[1..]) catch |err| {12        if (err == error.Usage) {13            std.debug.print("any: {s}\n\n{s}", .{ cli.lastErrorMessage(), cli.usage });14        } else {15            std.debug.print("any: {s}\n", .{@errorName(err)});16        }17        std.process.exit(1);18    };19}2021fn run(22    allocator: std.mem.Allocator,23    io: std.Io,24    args: []const [:0]const u8,25) !void {26    const action = try cli.parse(args);2728    switch (action) {29        .help => try printOut(io, "{s}", .{cli.usage}),30        .version => try printOut(io, "any {s}\n", .{build_options.version}),31        .print => try printOut(io, "{s}", .{skill.full}),32        .install => |options| {33            const target = options.path orelse try install.defaultPath(allocator);34            const outcome = try install.run(allocator, io, target, options);35            switch (outcome) {36                .created => try printOut(io, "created {s}\n", .{target}),37                .appended => try printOut(io, "appended {s} to {s}\n", .{ skill.name, target }),38                .replaced => try printOut(io, "replaced {s}\n", .{target}),39                .unchanged => try printOut(io, "{s} is already installed at {s}\n", .{ skill.name, target }),40                .absent => {41                    try printOut(io, "{s} is not installed at {s}\n", .{ skill.name, target });42                    std.process.exit(1);43                },44            }45        },46    }47}4849fn printOut(io: std.Io, comptime format: []const u8, args: anytype) !void {50    var buffer: [8192]u8 = undefined;51    var file_writer = std.Io.File.Writer.init(.stdout(), io, &buffer);52    try file_writer.interface.print(format, args);53    try file_writer.interface.flush();54}5556test {57    _ = cli;58    _ = install;59    _ = skill;60}