{"id":26040255,"url":"https://github.com/lygaen/clig","last_synced_at":"2026-06-10T07:31:12.635Z","repository":{"id":279049465,"uuid":"937577279","full_name":"Lygaen/clig","owner":"Lygaen","description":"CLI + Config loading for Zig ! Everything is setup to have almost no friction !","archived":false,"fork":false,"pushed_at":"2025-03-06T18:03:32.000Z","size":2373,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-06T19:22:13.814Z","etag":null,"topics":["cli","cli-parser","config","config-parser","library","zig","zig-library","ziglang"],"latest_commit_sha":null,"homepage":"https://lygaen.github.io/clig/","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Lygaen.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-23T12:08:14.000Z","updated_at":"2025-03-06T18:03:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"a682b4cd-9539-4198-a36d-142b04cb3d0a","html_url":"https://github.com/Lygaen/clig","commit_stats":null,"previous_names":["lygaen/clig"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lygaen%2Fclig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lygaen%2Fclig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lygaen%2Fclig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lygaen%2Fclig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lygaen","download_url":"https://codeload.github.com/Lygaen/clig/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242386700,"owners_count":20119573,"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":["cli","cli-parser","config","config-parser","library","zig","zig-library","ziglang"],"created_at":"2025-03-07T12:08:50.379Z","updated_at":"2025-12-08T07:01:54.702Z","avatar_url":"https://github.com/Lygaen.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Build](https://github.com/Lygaen/clig/actions/workflows/build.yml/badge.svg)\n![Docs](https://github.com/Lygaen/clig/actions/workflows/pages.yml/badge.svg)\n# CLI + Config for zig 0.14.0 !\n\nMany of the current libraries in zig only support for CLI command arguments or config loading but not both at the same time.\n\nThis library aims to solve that problem ! It aims to be as minimal as possible, and as much in compile-time as possible.\n\n## Installation\nRun the following command in your favourite terminal, in a folder containing a `build.zig.zon` :\n```sh\n$ zig fetch --save git+https://github.com/Lygaen/clig\n```\n\nAdd the dpendency to your `build.zig` :\n```zig\nconst std = @import(\"std\");\n\npub fn build(b: *std.Build) void {\n    // -- snip --\n\n    const clig_dep = b.dependency(\"clig\", .{\n        .target = target,\n        .optimize = optimize,\n    });\n\n    // Where `exe` represents your executable/library to link to\n    exe.linkLibrary(clig_dep.artifact(\"clig\"));\n\n    // -- snip --\n}\n```\n\nAnd voilà ! Everything is in order.\n\n## Usage\nYou can see the `example/` folder for an example usage of this library. It aims to be as less disruptive as possible :\n\nFirst import `clig` :\n```zig\nconst clig = @import(\"clig\");\n```\n\nDefine your config, it should be **default constructible** (aka. all fields should have defaults) :\n```zig\nconst Config = struct {\n    flag: u8 = 5,\n    string: []const u8 = \"default value\",\n    randoming: enum {\n        true_random,\n        prng,\n        cprng,\n    } = .true_random,\n    advanced: struct {\n        testify: bool = false,\n        random: u8 = 76,\n    } = .{},\n};\n```\n\nDefine a `help` struct that contains the description of the fields of `Config`, having the same name. \n\u003e Until we can add additional information to fields, this is the only solution to add compile-time information\n\u003e to a struct.\n```zig\nconst ConfigHelp = struct {\n    flag: []const u8 = \"Flag that does strictly nothing\",\n    string: []const u8 = \"Might want to set a variable as a string as well\",\n    randoming: []const u8 = \"Sets the useless type of randomness to use\",\n    advanced: struct {\n        testify: []const u8 = \"Type-ception is fun\",\n        random: []const u8 = \"Sets the randomness as to how much do nothing\",\n    } = .{},\n};\n```\n\nNow you can call `clig.init(#ConfigType, #Allocator, #InitOptions)` freely !\n```zig\npub fn main() !void {\n    // -- snip --\n\n    _ = clig.init(Config, allocator, .{\n        .help = .{\n            .title = \"Example\",\n            .preambule = \"CLIG Example CLI application that can do nothing ;)\",\n            .description = ConfigHelp,\n        },\n    }) catch |err| switch (err) {\n        error.HelpMessageShown =\u003e return, // Handle the case where help was shown\n        else =\u003e return err,\n    };\n    defer clig.deinit();\n}\n```\n\nAnd that's it ! If you have already a `Config` type defined, all you need is to add a `Helper` companion of the said type to add the descriptions.\nCLI arguments can be parsed using :\n`--arg=\u003cvalue\u003e` or `--arg value` or if the type is a bool `--arg` (to set to true).\n\nThe above types will generate the following configs and help message :\n```sh\n$ zig build run -- --help\nclig-example - Example\nCLIG Example CLI application that can do nothing ;)\n\nArguments :\n\n--flag \u003cu8\u003e\nDefault: 5 - Flag that does strictly nothing\n--string \u003cstring\u003e\nDefault: default value - Might want to set a variable as a string as well\n--randoming \u003ctrue_random,prng,cprng\u003e\nDefault: true_random - Sets the useless type of randomness to use\n\nSection advanced\n  --advanced.testify \u003cbool\u003e\n  Default: false - Type-ception is fun\n  --advanced.random \u003cu8\u003e\n  Default: 76 - Sets the randomness as to how much do nothing\n```\n\n```json\n$ cat config.json\n{\n\t\"flag\": 5,\n\t\"string\": \"default value\",\n\t\"randoming\": \"true_random\",\n\t\"advanced\": {\n\t\t\"testify\": false,\n\t\t\"random\": 76\n\t}\n}\n```\n\n\n## TODOs\n- [x] Config file loading\n- [x] Argument loading\n- [x] `=` in arguments loading\n- [x] Comptime Help\n- [x] More detailed documentation\n- [ ] ENV arguments\n- [ ] Better Errors\n- [ ] Revamp the example","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flygaen%2Fclig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flygaen%2Fclig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flygaen%2Fclig/lists"}