update clap, fix logs of optional types (#48)
* update clap, fix logs of optional types * rename empty test
This commit is contained in:
parent
e9d4c6d338
commit
4b04e50cf1
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2021 Jimmi Holst Christensen
|
||||
Copyright (c) 2022 Jimmi Holst Christensen
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
|
@ -5,6 +5,11 @@ README.md is autogenerated. Please edit example/README.md.template instead.
|
|||
|
||||
A simple and easy to use command line argument parser library for Zig.
|
||||
|
||||
The master branch of zig-clap targets the master branch of Zig. For a
|
||||
version of zig-clap that targets a specific Zig release, have a look
|
||||
at the releases. Each release specifies the Zig version it compiles with
|
||||
in the release notes.
|
||||
|
||||
## Features
|
||||
|
||||
* Short arguments `-a`
|
||||
|
@ -91,6 +96,7 @@ pub fn main() !void {
|
|||
const params = comptime clap.parseParamsComptime(
|
||||
\\-h, --help Display this help and exit.
|
||||
\\-n, --number <INT> An option parameter, which takes a value.
|
||||
\\-a, --answer <ANSWER> An option parameter which takes an enum.
|
||||
\\-s, --string <STR>... An option parameter which can be specified multiple times.
|
||||
\\<FILE>...
|
||||
\\
|
||||
|
@ -98,10 +104,12 @@ pub fn main() !void {
|
|||
|
||||
// Declare our own parsers which are used to map the argument strings to other
|
||||
// types.
|
||||
const YesNo = enum { yes, no };
|
||||
const parsers = comptime .{
|
||||
.STR = clap.parsers.string,
|
||||
.FILE = clap.parsers.string,
|
||||
.INT = clap.parsers.int(usize, 10),
|
||||
.ANSWER = clap.parsers.enumeration(YesNo),
|
||||
};
|
||||
|
||||
var diag = clap.Diagnostic{};
|
||||
|
@ -117,6 +125,8 @@ pub fn main() !void {
|
|||
debug.print("--help\n", .{});
|
||||
if (res.args.number) |n|
|
||||
debug.print("--number = {}\n", .{n});
|
||||
if (res.args.answer) |a|
|
||||
debug.print("--answer = {s}\n", .{@tagName(a)});
|
||||
for (res.args.string) |s|
|
||||
debug.print("--string = {s}\n", .{s});
|
||||
for (res.positionals) |pos|
|
|
@ -934,7 +934,7 @@ test "str and u64" {
|
|||
defer res.deinit();
|
||||
}
|
||||
|
||||
test "" {
|
||||
test "everything" {
|
||||
const params = comptime parseParamsComptime(
|
||||
\\-a, --aa
|
||||
\\-b, --bb
|
85
.gyro/zig-clap-Hejsil-github.com-1c09e0dc/pkg/clap/parsers.zig
vendored
Normal file
85
.gyro/zig-clap-Hejsil-github.com-1c09e0dc/pkg/clap/parsers.zig
vendored
Normal file
|
@ -0,0 +1,85 @@
|
|||
const std = @import("std");
|
||||
|
||||
const fmt = std.fmt;
|
||||
const testing = std.testing;
|
||||
|
||||
pub const default = .{
|
||||
.string = string,
|
||||
.str = string,
|
||||
.u8 = int(u8, 0),
|
||||
.u16 = int(u16, 0),
|
||||
.u32 = int(u32, 0),
|
||||
.u64 = int(u64, 0),
|
||||
.usize = int(usize, 0),
|
||||
.i8 = int(i8, 0),
|
||||
.i16 = int(i16, 0),
|
||||
.i32 = int(i32, 0),
|
||||
.i64 = int(i64, 0),
|
||||
.isize = int(isize, 0),
|
||||
.f32 = float(f32),
|
||||
.f64 = float(f64),
|
||||
};
|
||||
|
||||
pub fn string(in: []const u8) error{}![]const u8 {
|
||||
return in;
|
||||
}
|
||||
|
||||
test "string" {
|
||||
try testing.expectEqualStrings("aa", try string("aa"));
|
||||
}
|
||||
|
||||
pub fn int(comptime T: type, comptime radix: u8) fn ([]const u8) fmt.ParseIntError!T {
|
||||
return struct {
|
||||
fn parse(in: []const u8) fmt.ParseIntError!T {
|
||||
return fmt.parseInt(T, in, radix);
|
||||
}
|
||||
}.parse;
|
||||
}
|
||||
|
||||
test "int" {
|
||||
try testing.expectEqual(@as(u8, 0), try int(u8, 10)("0"));
|
||||
try testing.expectEqual(@as(u8, 1), try int(u8, 10)("1"));
|
||||
try testing.expectEqual(@as(u8, 10), try int(u8, 10)("10"));
|
||||
try testing.expectEqual(@as(u8, 0x10), try int(u8, 0)("0x10"));
|
||||
try testing.expectEqual(@as(u8, 0b10), try int(u8, 0)("0b10"));
|
||||
}
|
||||
|
||||
pub fn float(comptime T: type) fn ([]const u8) fmt.ParseFloatError!T {
|
||||
return struct {
|
||||
fn parse(in: []const u8) fmt.ParseFloatError!T {
|
||||
return fmt.parseFloat(T, in);
|
||||
}
|
||||
}.parse;
|
||||
}
|
||||
|
||||
test "float" {
|
||||
try testing.expectEqual(@as(f32, 0), try float(f32)("0"));
|
||||
}
|
||||
|
||||
pub const EnumError = error{
|
||||
NameNotPartOfEnum,
|
||||
};
|
||||
|
||||
pub fn enumeration(comptime T: type) fn ([]const u8) EnumError!T {
|
||||
return struct {
|
||||
fn parse(in: []const u8) EnumError!T {
|
||||
return std.meta.stringToEnum(T, in) orelse error.NameNotPartOfEnum;
|
||||
}
|
||||
}.parse;
|
||||
}
|
||||
|
||||
test "enumeration" {
|
||||
const E = enum { a, b, c };
|
||||
try testing.expectEqual(E.a, try enumeration(E)("a"));
|
||||
try testing.expectEqual(E.b, try enumeration(E)("b"));
|
||||
try testing.expectEqual(E.c, try enumeration(E)("c"));
|
||||
try testing.expectError(EnumError.NameNotPartOfEnum, enumeration(E)("d"));
|
||||
}
|
||||
|
||||
fn ReturnType(comptime P: type) type {
|
||||
return @typeInfo(P).Fn.return_type.?;
|
||||
}
|
||||
|
||||
pub fn Result(comptime P: type) type {
|
||||
return @typeInfo(ReturnType(P)).ErrorUnion.payload;
|
||||
}
|
|
@ -5,6 +5,11 @@ README.md is autogenerated. Please edit example/README.md.template instead.
|
|||
|
||||
A simple and easy to use command line argument parser library for Zig.
|
||||
|
||||
The master branch of zig-clap targets the master branch of Zig. For a
|
||||
version of zig-clap that targets a specific Zig release, have a look
|
||||
at the releases. Each release specifies the Zig version it compiles with
|
||||
in the release notes.
|
||||
|
||||
## Features
|
||||
|
||||
* Short arguments `-a`
|
|
@ -11,6 +11,7 @@ pub fn main() !void {
|
|||
const params = comptime clap.parseParamsComptime(
|
||||
\\-h, --help Display this help and exit.
|
||||
\\-n, --number <INT> An option parameter, which takes a value.
|
||||
\\-a, --answer <ANSWER> An option parameter which takes an enum.
|
||||
\\-s, --string <STR>... An option parameter which can be specified multiple times.
|
||||
\\<FILE>...
|
||||
\\
|
||||
|
@ -18,10 +19,12 @@ pub fn main() !void {
|
|||
|
||||
// Declare our own parsers which are used to map the argument strings to other
|
||||
// types.
|
||||
const YesNo = enum { yes, no };
|
||||
const parsers = comptime .{
|
||||
.STR = clap.parsers.string,
|
||||
.FILE = clap.parsers.string,
|
||||
.INT = clap.parsers.int(usize, 10),
|
||||
.ANSWER = clap.parsers.enumeration(YesNo),
|
||||
};
|
||||
|
||||
var diag = clap.Diagnostic{};
|
||||
|
@ -37,6 +40,8 @@ pub fn main() !void {
|
|||
debug.print("--help\n", .{});
|
||||
if (res.args.number) |n|
|
||||
debug.print("--number = {}\n", .{n});
|
||||
if (res.args.answer) |a|
|
||||
debug.print("--answer = {s}\n", .{@tagName(a)});
|
||||
for (res.args.string) |s|
|
||||
debug.print("--string = {s}\n", .{s});
|
||||
for (res.positionals) |pos|
|
|
@ -1,48 +0,0 @@
|
|||
const std = @import("std");
|
||||
|
||||
const fmt = std.fmt;
|
||||
|
||||
pub const default = .{
|
||||
.string = string,
|
||||
.str = string,
|
||||
.u8 = int(u8, 0),
|
||||
.u16 = int(u16, 0),
|
||||
.u32 = int(u32, 0),
|
||||
.u64 = int(u64, 0),
|
||||
.usize = int(usize, 0),
|
||||
.i8 = int(i8, 0),
|
||||
.i16 = int(i16, 0),
|
||||
.i32 = int(i32, 0),
|
||||
.i64 = int(i64, 0),
|
||||
.isize = int(isize, 0),
|
||||
.f32 = float(f32),
|
||||
.f64 = float(f64),
|
||||
};
|
||||
|
||||
pub fn string(in: []const u8) error{}![]const u8 {
|
||||
return in;
|
||||
}
|
||||
|
||||
pub fn int(comptime T: type, comptime radix: u8) fn ([]const u8) fmt.ParseIntError!T {
|
||||
return struct {
|
||||
fn parse(in: []const u8) fmt.ParseIntError!T {
|
||||
return fmt.parseInt(T, in, radix);
|
||||
}
|
||||
}.parse;
|
||||
}
|
||||
|
||||
pub fn float(comptime T: type) fn ([]const u8) fmt.ParseFloatError!T {
|
||||
return struct {
|
||||
fn parse(in: []const u8) fmt.ParseFloatError!T {
|
||||
return fmt.parseFloat(T, in);
|
||||
}
|
||||
}.parse;
|
||||
}
|
||||
|
||||
fn ReturnType(comptime P: type) type {
|
||||
return @typeInfo(P).Fn.return_type.?;
|
||||
}
|
||||
|
||||
pub fn Result(comptime P: type) type {
|
||||
return @typeInfo(ReturnType(P)).ErrorUnion.payload;
|
||||
}
|
2
deps.zig
2
deps.zig
|
@ -10,7 +10,7 @@ pub const pkgs = struct {
|
|||
pub const clap = Pkg{
|
||||
.name = "clap",
|
||||
.source = FileSource{
|
||||
.path = ".gyro/zig-clap-Hejsil-github.com-996821a3/pkg/clap.zig",
|
||||
.path = ".gyro/zig-clap-Hejsil-github.com-1c09e0dc/pkg/clap.zig",
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
git https://github.com/Hejsil/zig-clap.git master clap.zig 996821a3e1f186c9e5cdfd971d742c9815ea590e
|
||||
git https://github.com/mitchellh/zig-libxml2.git db7805026143d753a1deb84c23580d8050471223 libxml2.zig db7805026143d753a1deb84c23580d8050471223
|
||||
git https://github.com/Hejsil/zig-clap.git master clap.zig 1c09e0dc31918dd716b1032ad3e1d1c080cbbff1
|
||||
|
|
|
@ -1312,7 +1312,7 @@ fn genZigRegister(
|
|||
if (is_list) {
|
||||
if (std.mem.indexOf(u8, register.name, "[%s]") != null) {
|
||||
std.log.info("register name: {s}", .{register.name});
|
||||
std.log.info("dimension: {s}", .{dimension_opt});
|
||||
std.log.info("dimension: {?}", .{dimension_opt});
|
||||
return error.InvalidRegisterName;
|
||||
}
|
||||
|
||||
|
@ -1408,7 +1408,7 @@ fn genZigRegister(
|
|||
const array_prefix: []const u8 = if (dimension_opt) |dimension| blk: {
|
||||
if (dimension.increment != register.size.? / 8) {
|
||||
std.log.err("register: {s}", .{register.name});
|
||||
std.log.err("size: {}", .{register.size});
|
||||
std.log.err("size: {?}", .{register.size});
|
||||
std.log.err("dimension: {}", .{dimension});
|
||||
return error.InvalidArrayIncrement;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
test "" {
|
||||
test "all" {
|
||||
_ = @import("svd.zig");
|
||||
_ = @import("atdf.zig");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user