Update clap usage for most recent HEAD version

wch-ch32v003
Gregory Anders 3 years ago committed by Matt Knight
parent 1a1a281c01
commit b6821bf8c1

@ -18,6 +18,11 @@ const params = [_]clap.Param(clap.Help){
clap.parseParam("<POS>...") catch unreachable, clap.parseParam("<POS>...") catch unreachable,
}; };
const parsers = .{
.TYPE = clap.parsers.string,
.POS = clap.parsers.string,
};
pub fn main() !void { pub fn main() !void {
mainImpl() catch |err| switch (err) { mainImpl() catch |err| switch (err) {
error.Explained => std.process.exit(1), error.Explained => std.process.exit(1),
@ -41,17 +46,17 @@ fn mainImpl() anyerror!void {
defer _ = gpa.deinit(); defer _ = gpa.deinit();
var diag = clap.Diagnostic{}; var diag = clap.Diagnostic{};
var args = clap.parse(clap.Help, &params, .{ .diagnostic = &diag }) catch |err| { var res = clap.parse(clap.Help, &params, parsers, .{ .diagnostic = &diag }) catch |err| {
// Report useful error and exit // Report useful error and exit
diag.report(std.io.getStdErr().writer(), err) catch {}; diag.report(std.io.getStdErr().writer(), err) catch {};
return error.Explained; return error.Explained;
}; };
defer args.deinit(); defer res.deinit();
if (args.flag("--help")) if (res.args.help)
return clap.help(std.io.getStdErr().writer(), &params); return clap.help(std.io.getStdErr().writer(), clap.Help, &params);
var schema: ?Schema = if (args.option("--schema")) |schema_str| var schema: ?Schema = if (res.args.schema) |schema_str|
if (std.meta.stringToEnum(Schema, schema_str)) |s| s else { if (std.meta.stringToEnum(Schema, schema_str)) |s| s else {
std.log.err("Unknown schema type: {s}, must be one of: svd, atdf, json", .{schema_str}); std.log.err("Unknown schema type: {s}, must be one of: svd, atdf, json", .{schema_str});
return error.Explained; return error.Explained;
@ -59,8 +64,7 @@ fn mainImpl() anyerror!void {
else else
null; null;
const positionals = args.positionals(); var db = switch (res.positionals.len) {
var db = switch (positionals.len) {
0 => blk: { 0 => blk: {
if (schema == null) { if (schema == null) {
std.log.err("schema must be chosen when reading from stdin", .{}); std.log.err("schema must be chosen when reading from stdin", .{});
@ -80,10 +84,10 @@ fn mainImpl() anyerror!void {
1 => blk: { 1 => blk: {
// if schema is null, then try to determine using file extension // if schema is null, then try to determine using file extension
if (schema == null) { if (schema == null) {
const ext = std.fs.path.extension(positionals[0]); const ext = std.fs.path.extension(res.positionals[0]);
if (ext.len > 0) { if (ext.len > 0) {
schema = std.meta.stringToEnum(Schema, ext[1..]) orelse { schema = std.meta.stringToEnum(Schema, ext[1..]) orelse {
std.log.err("unable to determine schema from file extension of '{s}'", .{positionals[0]}); std.log.err("unable to determine schema from file extension of '{s}'", .{res.positionals[0]});
return error.Explained; return error.Explained;
}; };
} }
@ -95,7 +99,7 @@ fn mainImpl() anyerror!void {
} }
// all other schema types are xml based // all other schema types are xml based
const doc: *xml.Doc = xml.readFile(positionals[0].ptr, null, 0) orelse return error.ReadXmlFile; const doc: *xml.Doc = xml.readFile(res.positionals[0].ptr, null, 0) orelse return error.ReadXmlFile;
defer xml.freeDoc(doc); defer xml.freeDoc(doc);
break :blk try parseXmlDatabase(allocator, doc, schema.?); break :blk try parseXmlDatabase(allocator, doc, schema.?);

Loading…
Cancel
Save