{"id":13739474,"url":"https://github.com/travisstaloch/cmdlinezig","last_synced_at":"2025-05-08T19:34:11.026Z","repository":{"id":155683578,"uuid":"219254570","full_name":"travisstaloch/cmdlinezig","owner":"travisstaloch","description":"A simple command line parser","archived":true,"fork":false,"pushed_at":"2019-11-03T06:09:18.000Z","size":5,"stargazers_count":17,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-08-04T04:05:14.622Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/travisstaloch.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-11-03T05:08:32.000Z","updated_at":"2023-09-29T12:29:23.000Z","dependencies_parsed_at":"2024-01-25T01:12:04.908Z","dependency_job_id":null,"html_url":"https://github.com/travisstaloch/cmdlinezig","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/travisstaloch%2Fcmdlinezig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/travisstaloch%2Fcmdlinezig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/travisstaloch%2Fcmdlinezig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/travisstaloch%2Fcmdlinezig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/travisstaloch","download_url":"https://codeload.github.com/travisstaloch/cmdlinezig/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224758168,"owners_count":17364967,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T04:00:34.348Z","updated_at":"2024-11-15T09:30:36.607Z","avatar_url":"https://github.com/travisstaloch.png","language":"Zig","funding_links":[],"categories":["Applications"],"sub_categories":[],"readme":"## Simple command line parsing\n\nBased on a user defined struct.\n\n```zig\n// src/test.zig\nconst std = @import(\"std\");\nconst warn = std.debug.warn;\nconst clp = @import(\"parser.zig\");\n\nconst Args = struct {\n    name: []const u8 = \"\u003cname\u003e\",\n    windowed: bool = false,\n    width: u16 = 0,\n    x: f32 = 0,\n    xs: [10]i8 = [1]i8{0} ** 10,\n    u8s: [2]u8 = [1]u8{0} ** 2,\n};\n\npub fn main() anyerror!void {\n    var buf: [1024 * 4]u8 = undefined;\n    const a = \u0026std.heap.FixedBufferAllocator.init(buf[0..]).allocator;\n\n    var args = try clp.ArgParser(Args).init(a);\n    defer args.available.deinit();\n    try args.parse(a);\n\n    warn(\"args: {}\\n\", args.values);\n    args.show();\n    warn(\"name provided {}\\n\", args.available.get(\"name\").?.value);\n}\n\n```\n\n```bash\n$ zig run src/test.zig -- -xs 1 2 -u8s 1 2 3 4 --x -45 -name \"my name\"\nargs: Args{ .name = my name, .windowed = false, .width = 0, .x = -4.5e+01, .xs = i8@7fff092f7730, .u8s =  }\nname: my name\nx: -4.5e+01\nxs: 1, 2, 0, 0, 0, 0, 0, 0, 0, 0,\nu8s: 1, 2,\nname provided true\n```\n\n```bash\n$ zig build \u0026\u0026 ./zig-cache/bin/cmdlineparse -x -45\nargs: Args{ .name = \u003cname\u003e, .windowed = false, .width = 0, .x = -4.5e+01, .xs = i8@7ffe165b87a0, .u8s =  }\nx: -4.5e+01\nname provided false\n```\n\nYou must provide default values for each field of the Args struct as it will be instantiated with no arguments like: `Args{}`.\n\nThe parser is quite lenient in what it will accept:\n - Duplicate arguments are ignored.  Only the first value will be used.\n - Extra arguments are ignored.\n - Argument names are case sensitive.\n - Arguments may be provided with one or two hyphens (ie -a and --a are the same).\n - Array arguments: any number of values may be provided and only the first array.len will be applied.  The rest are ignored.\n - If an argument is provided and valid, args.available.get(\"field_name\").?.value will be set to true, otherwise false.\n   - Empty array arguments are valid.\n\nArgument supported types: Int, Float, Bool, Array, Slice of u8 (string)\n\nArray supported types: Int, Float, Bool\n\n\n### TODO\n - [ ] @Cleanup free std.mem.dupe'd slices\n - [ ] Maybe support slice types other than strings","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftravisstaloch%2Fcmdlinezig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftravisstaloch%2Fcmdlinezig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftravisstaloch%2Fcmdlinezig/lists"}