Show HN: Zli โ€“ A Batteries-Included CLI Framework for Zig

https://news.ycombinator.com/rss Hits: 4
Summary

๐Ÿ“Ÿ zli A blazing-fast, zero-cost CLI framework for Zig. The last one you will ever use. Build modular, ergonomic, and high-performance CLIs with ease. All batteries included. ๐Ÿงฑ Each command is modular and self-contained. inspired by Cobra (Go) and clap (Rust). ๐Ÿ“š Documentation See docs.md for full usage, examples, and internals. ๐Ÿš€ Highlights Modular commands & subcommands Fast flag parsing ( --flag , --flag=value , shorthand -abc ) , , shorthand ) Type-safe support for bool , int , string , , Named positional arguments with required , optional , variadic , , Auto help/version/deprecation handling Pretty help output with aligned flags & args Cobra-like usage hints, context-aware ๐Ÿ“ฆ Installation zig fetch --save=zli https://github.com/xcaeser/zli/archive/v3.5.1.tar.gz Add to your build.zig : const zli_dep = b . dependency ( "zli" , .{ . target = target }); exe . root_module . addImport ( "zli" , zli_dep . module ( "zli" )); ๐Ÿ—‚ Suggested Structure your-app/ โ”œโ”€โ”€ build.zig โ”œโ”€โ”€ src/ โ”‚ โ”œโ”€โ”€ main.zig โ”‚ โ””โ”€โ”€ cli/ โ”‚ โ”œโ”€โ”€ root.zig โ”‚ โ”œโ”€โ”€ run.zig โ”‚ โ””โ”€โ”€ version.zig Each command is in its own file You explicitly register subcommands root.zig is the entry point ๐Ÿงช Example // src/main.zig const std = @import ( "std" ); const cli = @import ( "cli/root.zig" ); pub fn main () ! void { const allocator = std . heap . smp_allocator ; var root = try cli . build ( allocator ); defer root . deinit (); try root . execute (.{}); // Or pass data with: try root.execute(.{ .data = &my_data }); } // src/cli/root.zig const std = @import ( "std" ); const zli = @import ( "zli" ); const run = @import ( "run.zig" ); const version = @import ( "version.zig" ); pub fn build ( allocator : std.mem.Allocator ) ! * zli.Command { const root = try zli . Command . init ( allocator , .{ . name = "blitz" , . description = "Your dev toolkit CLI" , }, showHelp ); try root . addCommands (&.{ try run . register ( allocator ), try version . register ( allocator ), }); return root ; } fn showHelp ( ctx : zli.CommandContext ) ! ...

First seen: 2025-05-25 18:45

Last seen: 2025-05-25 21:45