{"id":13741552,"url":"https://github.com/Gonzih/zigra","last_synced_at":"2025-05-08T21:34:21.236Z","repository":{"id":65254939,"uuid":"586740902","full_name":"Gonzih/zigra","owner":"Gonzih","description":"Command line toolkit for Zig","archived":false,"fork":false,"pushed_at":"2023-01-13T17:51:26.000Z","size":663,"stargazers_count":24,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-08-03T04:08:17.208Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Gonzih.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2023-01-09T05:36:40.000Z","updated_at":"2024-05-29T09:12:08.000Z","dependencies_parsed_at":"2023-01-15T23:31:11.859Z","dependency_job_id":null,"html_url":"https://github.com/Gonzih/zigra","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gonzih%2Fzigra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gonzih%2Fzigra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gonzih%2Fzigra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gonzih%2Fzigra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Gonzih","download_url":"https://codeload.github.com/Gonzih/zigra/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224774888,"owners_count":17367816,"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:01:00.230Z","updated_at":"2024-11-15T11:31:27.506Z","avatar_url":"https://github.com/Gonzih.png","language":"Zig","funding_links":[],"categories":["Libraries"],"sub_categories":[],"readme":"# Zigra\n\n![Zigra](zigra.jpg)\n\nCommand line toolkit for Zig.\nInspired by [cobra](https://github.com/spf13/cobra).\n\n* Separate each subcommand into its own package/file.\n* Command specific allocator accessible via Context (`ctx.allocator`).\n* Modular and composable API.\n\n# Example\n\n```zig\nconst std = @import(\"std\");\nconst zigra = @import(\"zigra\");\n\nconst Enum = enum {\n    Extract,\n    Transform,\n    Load,\n};\n\nconst Handler = struct {\n    pub const Self = @This();\n    v: usize = 0,\n\n    pub fn init(_: *Self, _: *zigra.Context) !void {}\n\n    pub fn run(_: *Self, ctx: *zigra.Context) !void {\n        std.debug.print(\"runner {s}\\n\", .{ctx.cmd});\n    }\n\n    pub fn deinit(_: *Self) void {}\n};\n\nconst SubHandler = struct {\n    pub const Self = @This();\n\n    verbose: bool = false,\n    threads: usize = 0,\n    kind: Enum = .Extract,\n    id: []const u8 = \"\",\n\n    pub fn init(self: *Self, ctx: *zigra.Context) !void {\n        try ctx.bind(bool, \u0026self.verbose, \"verbose\", \"v\", \"Verbose output\");\n        try ctx.bind(usize, \u0026self.threads, \"threads\", \"t\", \"Number of threads to run\");\n        try ctx.bind(Enum, \u0026self.kind, \"worker-kind\", \"w\", \"Which worker to run\");\n        try ctx.bind([]const u8, \u0026self.id, \"uuid\", \"u\", \"Unique identifier for the worker\");\n    }\n\n    pub fn run(self: *Self, ctx: *zigra.Context) !void {\n        std.debug.print(\"cmd: {s}\\n verbose: {}\\n threads: {}\\n kind: {any}\\n id: {s}\\n\", .{\n            ctx.cmd,\n            self.verbose,\n            self.threads,\n            self.kind,\n            self.id,\n        });\n    }\n\n    pub fn deinit(_: *Self) void {}\n};\n\nvar h1 = Handler{};\nvar r1 = zigra.Runner.make(\u0026h1);\n\nvar h2 = SubHandler{};\nvar r2 = zigra.Runner.make(\u0026h2);\n\npub fn main() !void {\n    const allocator = std.heap.page_allocator;\n\n    var root = try zigra.Command.init(allocator, \u0026r1, \"app\", \"My CLI App\");\n    var one = try zigra.Command.init(allocator, \u0026r2, \"one\", \"First subcommand\");\n    try root.addSubcommand(\u0026one);\n\n    defer root.deinit();\n    try root.exec();\n}\n```\n\n```\n./app --help\n\napp: My CLI App\n\n        Commands:\n                one: First subcommand\n\n        Arguments:\n                --verbose, -v (true or false): Verbose output\n                --threads, -t (integer): Number of threads to run\n                --worker-kind, -w (enum): Which worker to run\n                --uuid, -u (string): Unique identifier for the worker\n\n./app one --verbose=true --threads=20 --worker-kind=Extract --uuid=secret-id\n\n  cmd: one\n  verbose: false\n  threads: 20\n  kind: main.Enum.Extract\n  id: secret-id\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGonzih%2Fzigra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGonzih%2Fzigra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGonzih%2Fzigra/lists"}