00JCIV00/cova

What's going wrong here? std.fmt usage error

p7r0x7 opened this issue · 1 comments

p7r0x7 commented
const std = @import("std");
const cova = @import("cova");
const os = @import("std").os;
const mem = @import("std").mem;
const ascii = @import("std").ascii;
const builtin = @import("builtin");
pub usingnamespace @import("cova"); // Forward namespaces from the original module

const blue = "\x1b[34m";
const yell = "\x1b[93m";
const zero = "\x1b[0m";

/// Cova configuration type identity
pub const CommandT = cova.Command.Custom(.{
    .subcmds_help_fmt = "{s}:\t" ++ blue ++ "{s}" ++ zero,
    .val_config = .{
        .vals_help_fmt = "{s} ({s}):\t" ++ blue ++ "{s}" ++ zero,
        .set_behavior = .Last,
        .arg_delims = ",;",
    },
    .opt_config = .{
        .help_fn = struct {
            fn help(self: anytype, writer: anytype) !void {
                try self.usage(writer);
                try writer.print(
                    "\n{?s}{?s}{s}",
                    .{ CommandT.indent_fmt, CommandT.indent_fmt, self.description },
                );
            }
        }.help,
        .usage_fmt = "{c}{?c}{s}{?s} " ++ yell ++ "\"{s}({s})\"" ++ zero,
        .allow_abbreviated_long_opts = false,
        .allow_opt_val_no_space = true,
        .opt_val_seps = "=:",
        .short_prefix = null,
        .long_prefix = "-",
    },
    .indent_fmt = "    ",
});

///
pub const setup_cmd: CommandT = .{
    .name = "vpxl",
    .description = "a VP9 encoder by Matt R Bonnette",
    .opts = &.{
        pathOption("mkv", "input_path", ""),
        pathOption("y4m", "input_path", ""),
        pathOption("yuv", "input_path", ""),
        pathOption("webm", "output_path", ""),
        pathOption("ivf", "output_path", ""),
        boolOption("resume", "don't be dummy and disable this, this is necessary for thine happiness <3"),
    },
};

pub fn boolOption(comptime name: []const u8, comptime description: []const u8) CommandT.OptionT {
    return .{
        .name = name,
        .long_name = name,
        .description = description,
        .val = CommandT.ValueT.ofType(bool, .{ .name = "", .parse_fn = struct {
            pub fn parseBool(arg: []const u8) !bool {
                const T = [_][]const u8{ "1", "true", "t", "yes", "y" };
                const F = [_][]const u8{ "0", "false", "f", "no", "n" };
                for (T) |str| if (ascii.eqlIgnoreCase(str, arg)) return true;
                for (F) |str| if (ascii.eqlIgnoreCase(str, arg)) return false;
                return error.InvalidBooleanValue;
            }
        }.parseBool }),
    };
}

pub fn pathOption(comptime name: []const u8, comptime val: []const u8, comptime description: []const u8) CommandT.OptionT {
    return .{
        .name = name,
        .long_name = name,
        .description = description,
        .val = CommandT.ValueT.ofType([]const u8, .{ .name = val ++ " ", .parse_fn = struct {
            pub fn parsePath(arg: []const u8) ![]const u8 {
                os.access(arg, os.F_OK) catch |err| {
                    // No way to return a path to stdin/out/err on Windows, so this will have to be handled outside Cova
                    if (mem.eql(u8, arg, "-")) return arg;
                    return err;
                };
                return arg;
            }
        }.parsePath }),
    };
}
p7r0x7@Peroxide-2 ~/D/vpxl> zig build run -- -ivf=-l -y4m:- -resume=1 -help
zig build-exe vpxl Debug native: error: the following command failed with 1 compilation errors:
/Users/p7r0x7/zig/zig build-exe /Users/p7r0x7/Documents/vpxl/src/main.zig -I/opt/homebrew/Cellar/zimg/3.0.5/include -L/opt/homebrew/Cellar/zimg/3.0.5/lib -lzimg --cache-dir /Users/p7r0x7/Documents/vpxl/zig-cache --global-cache-dir /Users/p7r0x7/.cache/zig --name vpxl --mod cova::/Users/p7r0x7/.cache/zig/p/1220ba88327fe4535cd026593b3bb6393f1f89f9ff6c67a71fa9587660fa3f96e11b/src/cova.zig --deps cova --listen=- 
Build Summary: 0/5 steps succeeded; 1 failed (disable with --summary none)
run transitive failure
└─ run vpxl transitive failure
   ├─ zig build-exe vpxl Debug native 1 errors
   └─ install transitive failure
      └─ install vpxl transitive failure
         └─ zig build-exe vpxl Debug native (reused)
/Users/p7r0x7/zig/lib/std/fmt.zig:459:5: error: invalid format string 's' for type 'Value.Custom(.{.set_behavior = .Last, .arg_delims = ",;", .custom_types = .{  }, .use_custom_bit_width_range = false, .min_int_bit_width = 1, .max_int_bit_width = 256, .help_fn = null, .usage_fn = null, .indent_fmt = "    ", .vals_usage_fmt = "\"{s} ({s})\"", .vals_help_fmt = "{s} ({s}):\t\x1b[34m{s}\x1b[0m"})'
    @compileError("invalid format string '" ++ fmt ++ "' for type '" ++ @typeName(@TypeOf(value)) ++ "'");
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    formatType__anon_6139: /Users/p7r0x7/zig/lib/std/fmt.zig:566:53
    format__anon_6127: /Users/p7r0x7/zig/lib/std/fmt.zig:184:23
    remaining reference traces hidden; use '-freference-trace' to see all reference traces
p7r0x7@Peroxide-2 ~/D/vpxl [2]>
p7r0x7 commented

Oh this was my mistake on a separate document.