{"id":28286746,"url":"https://github.com/xcaeser/zli","last_synced_at":"2026-06-29T01:31:49.058Z","repository":{"id":293341776,"uuid":"983732269","full_name":"xcaeser/zli","owner":"xcaeser","description":"📟 Build ergonomic, high-performance command-line tools (CLI) with zig.","archived":false,"fork":false,"pushed_at":"2026-06-16T11:20:33.000Z","size":222,"stargazers_count":323,"open_issues_count":3,"forks_count":14,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-06-16T13:16:53.977Z","etag":null,"topics":["cli","zig","zig-package"],"latest_commit_sha":null,"homepage":"https://xcaeser.github.io/zli/","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/xcaeser.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-05-14T20:39:08.000Z","updated_at":"2026-06-09T22:52:11.000Z","dependencies_parsed_at":"2025-05-14T21:41:16.754Z","dependency_job_id":"f412c3dd-4c7d-4c3f-bcb1-fbee5a882c15","html_url":"https://github.com/xcaeser/zli","commit_stats":null,"previous_names":["xcaeser/zli"],"tags_count":36,"template":false,"template_full_name":null,"purl":"pkg:github/xcaeser/zli","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xcaeser%2Fzli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xcaeser%2Fzli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xcaeser%2Fzli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xcaeser%2Fzli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xcaeser","download_url":"https://codeload.github.com/xcaeser/zli/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xcaeser%2Fzli/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34910177,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-28T02:00:05.809Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","zig","zig-package"],"created_at":"2025-05-21T21:12:35.927Z","updated_at":"2026-06-29T01:31:49.041Z","avatar_url":"https://github.com/xcaeser.png","language":"Zig","funding_links":[],"categories":["Zig","Language Essentials"],"sub_categories":["Command Line and Argument Parser"],"readme":"### 📟 zli - a blazing-fast CLI framework for Zig.\n\nBuild modular, ergonomic, and high-performance CLIs with ease.\n\nBatteries included. [ZLI reference docs](https://xcaeser.github.io/zli)\n\n[![Tests](https://github.com/xcaeser/zli/actions/workflows/main.yml/badge.svg)](https://github.com/xcaeser/zli/actions/workflows/main.yml)\n[![Zig Version](https://img.shields.io/badge/Zig_Version-0.16.0-orange.svg?logo=zig)](README.md)\n[![License: MIT](https://img.shields.io/badge/License-MIT-lightgrey.svg?logo=cachet)](LICENSE)\n[![Built by xcaeser](https://img.shields.io/badge/Built%20by-@xcaeser-blue)](https://github.com/xcaeser)\n[![Version](https://img.shields.io/badge/ZLI-v5.1.1-green)](https://github.com/xcaeser/zli/releases)\n\n## 🚀 Features\n\n- Modular commands \u0026 subcommands\n- Fast flag parsing (`--flag`, `--flag=value`, shorthand `-abc`)\n- Type-safe support for `bool`, `int`, `string`\n- Named positional arguments with `required`, `optional`, `variadic`\n- Auto help/version/deprecation handling\n- Pretty help output with aligned flags \u0026 args\n- Spinners for a more interactive experience\n- Usage hints, context-aware\n\n## 📦 Installation\n\n```sh\nzig fetch --save=zli https://github.com/xcaeser/zli/archive/v5.1.1.tar.gz\n```\n\nAdd to your `build.zig`:\n\n```zig\nconst zli_dep = b.dependency(\"zli\", .{ .target = target, .optimize = optimize });\nexe.root_module.addImport(\"zli\", zli_dep.module(\"zli\"));\n```\n\n## 🌱 Single-file Quick Start\n\nStart with one `src/main.zig`: initialize the root command, add a flag, add a subcommand, then run it.\n\n```zig\nconst std = @import(\"std\");\nconst Io = std.Io;\nconst zli = @import(\"zli\");\n\npub fn main(init: std.process.Init) !void {\n    const io = init.io;\n\n    var wbuf: [1024]u8 = undefined;\n    var stdout_writer = Io.File.Writer.init(.stdout(), io, \u0026wbuf);\n    const stdout = \u0026stdout_writer.interface;\n    defer stdout.flush() catch {};\n\n    var rbuf: [1024]u8 = undefined;\n    var stdin_reader = Io.File.Reader.init(.stdin(), io, \u0026rbuf);\n    const stdin = \u0026stdin_reader.interface;\n\n    const init_options = zli.InitOptions{\n        .allocator = init.gpa,\n        .io = io,\n        .writer = stdout,\n        .reader = stdin,\n    };\n\n    const root = try zli.Command.init(init_options, .{\n        .name = \"hello\",\n        .description = \"A tiny zli app\",\n        .version = .{ .major = 0, .minor = 1, .patch = 0, .pre = null, .build = null },\n    }, showHelp);\n\n    try root.addFlag(.{\n        .name = \"verbose\",\n        .shortcut = \"v\",\n        .description = \"Print more details\",\n        .type = .Bool,\n        .default_value = .{ .Bool = false },\n        .persistent = true,\n    });\n\n    const greet = try zli.Command.init(init_options, .{\n        .name = \"greet\",\n        .description = \"Greet someone\",\n    }, greetSomeone);\n    try greet.addPositionalArg(.{\n        .name = \"name\",\n        .description = \"Who to greet\",\n        .required = true,\n    });\n    try root.addCommand(greet);\n\n    var args_iter = init.minimal.args.iterate();\n    root.runAndExit(\u0026args_iter, .{});\n}\n\nfn showHelp(ctx: zli.CommandContext) !void {\n    try ctx.command.printHelp();\n}\n\nfn greetSomeone(ctx: zli.CommandContext) !void {\n    const verbose = ctx.flag(\"verbose\", bool);\n    const name = ctx.getArg(\"name\") orelse \"friend\";\n\n    if (verbose) {\n        try ctx.writer.print(\"Preparing greeting for {s}\\n\", .{name});\n    }\n\n    try ctx.writer.print(\"Hello, {s}!\\n\", .{name});\n}\n```\n\nRun it:\n\n```sh\nzig build run -- greet Ada\nzig build run -- --verbose greet Ada\nzig build run -- greet Ada --help\n```\n\nUse `runAndExit` for normal CLI binaries: it prints errors/help and exits with the right process code. Use `execute` when you want library-friendly behavior for tests, embedding, or custom error handling; it returns errors instead of exiting the process.\n\n## 🗂 Folder Structure (but you can do what you want)\n\n```\nyour-app/\n├── build.zig\n├── src/\n│   ├── main.zig\n│   └── cli/\n│       ├── root.zig // zli entrypoint\n│       ├── run.zig  // subcommand 1\n│       └── version.zig // subcommand 1\n        ... // subcommand of subcommands, go nuts\n```\n\n- Each command is in its own file\n- You explicitly register subcommands\n- `root.zig` is the entry point\n\n## 🧪 Example\n\n### Your program\n\n```zig\n// src/main.zig\nconst std = @import(\"std\");\nconst Io = std.Io;\n\nconst cli = @import(\"cli/root.zig\");\n\npub fn main(init: std.process.Init) !void {\n    const io = init.io;\n\n    var wbuf: [1024]u8 = undefined;\n    var stdout_writer = Io.File.Writer.init(.stdout(), io, \u0026wbuf);\n    const stdout = \u0026stdout_writer.interface;\n    defer stdout.flush() catch {};\n\n    var rbuf: [1024]u8 = undefined;\n    var stdin_reader = Io.File.Reader.init(.stdin(), io, \u0026rbuf);\n    const stdin = \u0026stdin_reader.interface;\n\n    const root = try cli.build(.{\n        .allocator = init.gpa,\n        .io = io,\n        .writer = stdout,\n        .reader = stdin,\n    });\n\n    var argsIter = init.minimal.args.iterate();\n    root.runAndExit(\u0026argsIter, .{}); // Or pass data with: root.runAndExit(\u0026argsIter, .{ .data = \u0026my_data });\n}\n```\n\n### Root command - entrypoint\n\n```zig\n// src/cli/root.zig\nconst std = @import(\"std\");\nconst zli = @import(\"zli\");\n\nconst run = @import(\"run.zig\");\nconst version = @import(\"version.zig\");\n\npub fn build(init_options: zli.InitOptions) !*zli.Command {\n    const root = try zli.Command.init(init_options, .{\n        .name = \"blitz\",\n        .description = \"Your dev toolkit CLI\",\n        .version = .{ .major = 0, .minor = 0, .patch = 1, .pre = null, .build = null },\n    }, showHelp);\n\n    try root.addCommands(\u0026.{\n        try run.register(init_options),\n        try version.register(init_options),\n    });\n\n    return root;\n}\n\nfn showHelp(ctx: zli.CommandContext) !void {\n    try ctx.command.printHelp();\n}\n```\n\n### Run subcommand\n\n```zig\n// src/cli/run.zig\nconst std = @import(\"std\");\nconst zli = @import(\"zli\");\n\nconst now_flag = zli.Flag{\n    .name = \"now\",\n    .shortcut = \"n\",\n    .description = \"Run immediately\",\n    .type = .Bool,\n    .default_value = .{ .Bool = false },\n};\n\npub fn register(init_options: zli.InitOptions) !*zli.Command {\n    const cmd = try zli.Command.init(init_options, .{\n        .name = \"run\",\n        .description = \"Run your workflow\",\n    }, run);\n\n    try cmd.addFlag(now_flag);\n    try cmd.addPositionalArg(.{\n        .name = \"script\",\n        .description = \"Script to execute\",\n        .required = true,\n    });\n    try cmd.addPositionalArg(.{\n        .name = \"env\",\n        .description = \"Environment name\",\n        .required = false,\n    });\n\n    return cmd;\n}\n\nfn run(ctx: zli.CommandContext) !void {\n    const now = ctx.flag(\"now\", bool); // type-safe flag access\n\n    const script = ctx.getArg(\"script\") orelse {\n        try ctx.writer.print(\"Missing script arg\\n\", .{});\n        return;\n    };\n    const env = ctx.getArg(\"env\") orelse \"default\";\n\n    std.debug.print(\"Running {s} in {s} (now = {})\\n\", .{ script, env, now });\n\n    // You can also get other commands by name:\n    // if (ctx.root.findCommand(\"create\")) |create_cmd| {\n    //    try create_cmd.printUsageLine();\n    // }\n\n    // if you passed data to your root command, you can access it here:\n    // const object = ctx.getContextData(type_of_your_data); // can be struct, []const u8, etc., object is a pointer.\n\n};\n```\n\n### Version subcommand\n\n```zig\n// src/cli/version.zig\nconst std = @import(\"std\");\nconst zli = @import(\"zli\");\n\npub fn register(init_options: zli.InitOptions) !*zli.Command {\n    return zli.Command.init(init_options, .{\n        .name = \"version\",\n        .shortcut = \"v\",\n        .description = \"Show CLI version\",\n    }, show);\n}\n\nfn show(ctx: zli.CommandContext) !void {\n    try ctx.root.printVersion();\n}\n```\n\n### Spinners example\n\nAvailable functions:\n\n- `spinner.start`: to add a new line. sets the spinner to running\n- `spinner.updateStyle`: to update the spinner style\n- `spinner.updateMessage`: to update text of a running spinner\n- `spinner.succeed`, `fail`, `info`, `preserve`: mandatory to complete a line you started. each `spinner.start` needs a `spinner.succeed`, `fail` etc.. spinner after this action is done for that specific line\n- Recommendation: use `spinner.print` instead of your own `writer.print` to not have non-displayed messages as spinner works on its own thread\n\n```zig\nconst std = @import(\"std\");\nconst zli = @import(\"zli\");\n\npub fn run(ctx: zli.CommandContext) !void {\n    const spinner = ctx.spinner;\n    spinner.updateStyle(.{ .frames = zli.SpinnerStyles.earth, .refresh_rate_ms = 150 }); // many styles available\n\n    // Step 1\n    try spinner.start(\"Step 1\", .{}); // New line\n    std.Thread.sleep(2000 * std.time.ns_per_ms);\n\n    try spinner.succeed(\"Step 1 success\", .{}); // each start must be closed with succeed, fail, info, preserve\n\n    spinner.updateStyle(.{ .frames = zli.SpinnerStyles.weather, .refresh_rate_ms = 150 }); // many styles available\n\n    // Step 2\n    try spinner.start(\"Step 2\", .{}); // New line\n    std.Thread.sleep(3000 * std.time.ns_per_ms);\n\n    spinner.updateStyle(.{ .frames = zli.SpinnerStyles.dots, .refresh_rate_ms = 150 }); // many styles available\n    try spinner.updateMessage(\"Step 2: Calculating things...\", .{}); // update the text of step 2\n\n    const i = work(); // do some work\n\n    try spinner.info(\"Step 2 info: {d}\", .{i});\n\n    // Step 3\n    try spinner.start(\"Step 3\", .{});\n    std.Thread.sleep(2000 * std.time.ns_per_ms);\n\n    try spinner.fail(\"Step 3 fail\", .{});\n\n    try spinner.print(\"Finish\\n\", .{}); // instead of using ctx.writer or another writer to avoid concurrency issues\n}\n\nfn work() u128 {\n    var i: u128 = 1;\n    for (0..100000000) |t| {\n        i = (t + i);\n    }\n\n    return i;\n}\n```\n\n## ✅ Features Checklist\n\n- [x] Commands \u0026 subcommands\n- [x] Command aliases\n- [x] Flags \u0026 shorthands\n- [x] Type-safe flag values\n- [x] Positional args (required, optional, variadic)\n- [x] Named access: `ctx.getArg(\"name\")`\n- [x] Context data\n- [x] Help/version auto handling\n- [x] Deprecation notices\n- [x] Pretty-aligned help for flags \u0026 args\n- [x] Clean usage output like Cobra\n- [x] Spinners and loading state (very powerful)\n- [x] Persistent flags\n\n## 📚 Documentation\n\nSee [docs](https://xcaeser.github.io/zli/) for full usage, examples, and internals.\n\n## 📝 License\n\nMIT. See [LICENSE](LICENSE). Contributions welcome.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxcaeser%2Fzli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxcaeser%2Fzli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxcaeser%2Fzli/lists"}