I am a newbie in zig trying to read command line arguments, handling and checking them.
getting : error struct has no member named …
const std = @import("std");
// TEST [/L=<filename> or empty=screen] [/DL]");
const Arguments = struct {
log : [] u8 ,
logging : bool ,
debugtolog : bool ,
//pub fn setLogging ( setlog: bool ) void {
// std.debug.print("true", .{});
// logging = setlog;
//}
};
fn checkMinimumArguments() !void {
const minargs: u8 = 1;
const maxargs: u8 = 2;
var rc: bool = false;
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
defer _ = gpa.deinit();
const args = try std.process.argsAlloc(allocator);
defer std.process.argsFree(allocator, args);
std.debug.print("There are {d} args:\n", .{args.len});
if (args.len < minargs or args.len > maxargs) {
std.debug.print("Usage:\n", .{});
std.debug.print(" TEST [/L=<filename> or empty=screen] [/DL]", .{});
}
for(args) |arg| {
std.debug.print(" {s}\n", .{arg});
}
rc = checklogging(args);
// .. other commandline arguments
}
fn checklogging(args: [][:0] u8) bool {
const logparmtext = "/L=";
// const debuglogparmtext = "/DL";
var str_found: bool = false;
for (args) |value| {
if ( std.mem.startsWith(u8, value, logparmtext) ) {
std.debug.print("true", .{});
str_found = true;
}
else {
std.debug.print("false", .{});
str_found = false;
}
}
//Arguments.setLogging ( str_found );
Arguments.logging = str_found;
return str_found;
}
pub fn main() !void {
try checkMinimumArguments();
}