v7.1.02026-11-16
zli v7.1.0 更新说明
这版新增了 InitOptions.environmap 配置项:从 main 传入 init.environmap,之后所有命令都能通过 ctx.environ_map 读取进程环境变量。该选项可选,老项目不改动也能正常编译,升级无负担。
另外修正了 CI 环境——之前测试和文档构建没有跑在 zli 实际要求的 Zig 0.17.1 版本上,现已对齐,README 徽章也一并改成 0.17.1,避免误导后来的开发者。
v7.0.02026-11-09
zli v7.0.0 是破坏性更新:addCommand/addCommands 改为返回 CommandSetupErrors!void,新增 DuplicateCommand。过去重复添加命令、给命令重复挂父或自我/祖先添加会造成泄漏、双重释放甚至 deinit 卡死,现在直接拒绝并打印一行提示,出错时命令仍由你释放。持久 flag 改为单一定义,子命令经父链读取,同名时自身定义(含快捷键)优先,不再取决于添加顺序。内置 help 不再持久,每个命令各有一份,根上重定义不影响子命令。新增 CommandOptions.help_footer,在该命令帮助末尾打印自定义文字。
修复:重复 run/execute 会残留上次的 flag,app --help 后再 app 又打印一遍帮助;flag 重定义未清掉旧快捷键;help 被改成非 Bool 类型会 panic;spinner 的 Ctrl+C 处理器只在运行时装上、stop 时还原,不再吞掉应用或留下多余转义序列;全部 flag 隐藏时帮助页少一行空行。现需 Zig 0.17.1。
v6.1.02026-11-08
zli v6.1.0
Changed
- A command with a variadic positional argument takes every word after its first positional as a positional, including words that start with - or --. With a variadic command on app shell, app shell ls -la passes ls and -la, and app shell cat --help passes cat and --help instead of showing help. Flags before the first positional (app shell --help, app shell -h) still parse, and commands without a variadic argument are unchanged. To give such a command a flag, put it before the first positional.
zli v6.0.0
A major release: a rewritten spinner, a leaner parser and help renderer (src/zli.zig shrinks from 1110 to 834 lines), and 14 bug fixes. It needs Zig 0.17.0, and a few APIs changed (see below).
Breaking changes
- Zig 0.17.0 is now the minimum version.
- Spinner.init no longer takes a reader. It is now Spinner.init(io, writer, allocator, options). Commands that use ctx.spinner need no change.
- Spinner.SpinnerOptions is renamed to Spinner.Options.
- Spinner frames no longer end in a space. The spinner adds the gap itself. Remove the trailing space from custom frames, or you'll get two.
- Spinner.styles is private. Use zli.styles.
- SpinnerStyles.circlehalvess is renamed to circlehalves.
- Command.maxlen is removed.
- runAndExit prints error: <Name> when a command's own function returns an error, instead of exiting 1 silently. zli's own parse errors still print only their usual message.
- Deprecated commands are hidden from help listings. They still run and print their deprecation notice.
``zig
// v5
var spinner = zli.Spinner.init(io, writer, reader, allocator, .{});
const options: zli.Spinner.SpinnerOptions = .{ .frames = &.{ "+ ", "x " } };
// v6
var spinner = zli.Spinner.init(io, writer, allocator, .{});
const options: zli.Spinner.Options = .{ .frames = &.{ "+", "x" } };
`
Added
- Command.run, which works like runAndExit but returns the exit code instead of exiting.
- spinner.warn(), a yellow ⚠ line.
- succeed, fail, warn, info and preserve work without a start(), for one-off status lines.
Fixed
Spinner
- When output is piped or redirected (CI logs, > file), nothing animates. Only the finished lines are printed, without colors or escape codes.
- stop(), succeed() and the other finishers return immediately. Before, they waited up to one refresh interval.
- Ctrl+C while a spinner runs restores the hidden cursor before the process exits.
- Messages wider than the terminal are clipped instead of leaving a trail of wrapped lines.
Parsing
- An empty argv, or an empty argument (app echo ""), no longer crashes.
- An unknown subcommand is reported as an error. Before, the parent command ran silently and exited 0.
- Persistent flags given before a subcommand (app --verbose greet) now reach it. --help is persistent too, so app --help greet shows greet's help.
- -h and --help after -- are positional arguments.
- Flags whose name starts with no- (e.g. --no-cache) can be set.
- The long form of a shortcut (--t=2) sets the flag.
- ctx.flag() reads a flag by its shortcut.
- Negative numbers outside the i32 range, or with decimals (-1.5), are positional arguments instead of flag groups.
- ctx.flag() panics with the flag's name on a misspelled name, instead of undefined behavior in release builds.
- ctx.flag() saturates ints that don't fit the requested type instead of panicking.
Help and output
- Hidden flags no longer appear in help.
- Flags are sorted by name.
- Command, flag and argument descriptions line up in one column.
- Multi-line descriptions stay aligned (#14).
- Error output is flushed even when the caller skips its own flush.
Platforms and memory
- zli builds for Windows and WASI. Argument parsing no longer reads a POSIX-only field of the args iterator.
- Command.init` frees everything when an allocation fails.
Full changelog: https://github.com/xcaeser/zli/compare/v5.1.4...v6.0.0
v6.0.02026-10-16
zli v6.0.0
A major release: a rewritten spinner, a leaner parser and help renderer (src/zli.zig shrinks from 1110 to 834 lines), and 14 bug fixes. It needs Zig 0.17.0, and a few APIs changed (see below).
Breaking changes
- Zig 0.17.0 is now the minimum version.
- Spinner.init no longer takes a reader. It is now Spinner.init(io, writer, allocator, options). Commands that use ctx.spinner need no change.
- Spinner.SpinnerOptions is renamed to Spinner.Options.
- Spinner frames no longer end in a space. The spinner adds the gap itself. Remove the trailing space from custom frames, or you'll get two.
- Spinner.styles is private. Use zli.styles.
- SpinnerStyles.circlehalvess is renamed to circlehalves.
- Command.maxlen is removed.
- runAndExit prints error: <Name> when a command's own function returns an error, instead of exiting 1 silently. zli's own parse errors still print only their usual message.
- Deprecated commands are hidden from help listings. They still run and print their deprecation notice.
``zig
// v5
var spinner = zli.Spinner.init(io, writer, reader, allocator, .{});
const options: zli.Spinner.SpinnerOptions = .{ .frames = &.{ "+ ", "x " } };
// v6
var spinner = zli.Spinner.init(io, writer, allocator, .{});
const options: zli.Spinner.Options = .{ .frames = &.{ "+", "x" } };
`
Added
- Command.run, which works like runAndExit but returns the exit code instead of exiting.
- spinner.warn(), a yellow ⚠ line.
- succeed, fail, warn, info and preserve work without a start(), for one-off status lines.
Fixed
Spinner
- When output is piped or redirected (CI logs, > file), nothing animates. Only the finished lines are printed, without colors or escape codes.
- stop(), succeed() and the other finishers return immediately. Before, they waited up to one refresh interval.
- Ctrl+C while a spinner runs restores the hidden cursor before the process exits.
- Messages wider than the terminal are clipped instead of leaving a trail of wrapped lines.
Parsing
- An empty argv, or an empty argument (app echo ""), no longer crashes.
- An unknown subcommand is reported as an error. Before, the parent command ran silently and exited 0.
- Persistent flags given before a subcommand (app --verbose greet) now reach it. --help is persistent too, so app --help greet shows greet's help.
- -h and --help after -- are positional arguments.
- Flags whose name starts with no- (e.g. --no-cache) can be set.
- The long form of a shortcut (--t=2) sets the flag.
- ctx.flag() reads a flag by its shortcut.
- Negative numbers outside the i32 range, or with decimals (-1.5), are positional arguments instead of flag groups.
- ctx.flag() panics with the flag's name on a misspelled name, instead of undefined behavior in release builds.
- ctx.flag() saturates ints that don't fit the requested type instead of panicking.
Help and output
- Hidden flags no longer appear in help.
- Flags are sorted by name.
- Command, flag and argument descriptions line up in one column.
- Multi-line descriptions stay aligned (#14).
- Error output is flushed even when the caller skips its own flush.
Platforms and memory
- zli builds for Windows and WASI. Argument parsing no longer reads a POSIX-only field of the args iterator.
- Command.init` frees everything when an allocation fails.
Full changelog: https://github.com/xcaeser/zli/compare/v5.1.4...v6.0.0
v5.1.42026-10-02
zli v5.1.4 修复了一个输出污染问题:命令结束时不再向标准输出写入显示光标的转义序列 ESC[?25h。此前 Spinner.deinit 会无条件输出该序列,导致它混进管道和重定向捕获的结果里;实际上 spinner 运行期间 stop() 已经会正常恢复光标,这次修复消除了多余的残留。如果你用 zli 的输出做管道处理或脚本解析,升级后拿到的内容会更干净。
v5.1.32026-08-20
zli v5.1.3
参数解析逻辑做了改进:位置参数和标志参数现在可以任意顺序混排,怎么写都能正确识别。以前必须按固定顺序输入,容易报错,这版之后随手敲就行,用起来顺手不少。
v5.1.22026-07-04
zli v5.1.2 发布,这是一个修复版本。本次调整了命令行加载动画(spinner)的刷新逻辑,此前动画输出可能存在未及时清空、残留闪烁的问题,现在刷新更干净,终端显示不再出现多余字符堆积。如果你在使用过程中遇到过进度提示显示错乱的情况,升级到此版本即可解决。功能上没有其他改动,建议所有用户直接更新。
v5.1.12026-06-18
zli v5.1.1 是一次补丁更新,主要打磨帮助信息。常规命令的帮助输出末尾原本带有一段多余的提示文字,现已删除,--help 结果更干净。同时把包版本元数据更新为 5.1.1,方便依赖检测正确识别当前版本。功能与行为无变化,建议直接升级。
v5.1.02026-06-18
zli v5.1.0 主打解析流程重构、持久化标志和更顺手的入门体验。
先说破坏性变更:Command.execute 不再直接退出进程,改为返回解析/执行错误,方便测试、嵌入和自定义错误处理;完整 CLI 二进制应改用新增的 Command.runAndExit,以进程退出码收尾。解析器重写为单一路径,统一处理命令遍历、长选项、分组短选项、选项值和位置参数,缺失值、非法值、未知选项、未知命令及位置参数个数不匹配的报错也一并收紧。
功能方面,新增 .persistent = true 持久化标志,父命令的选项会自动对已注册子命令生效;--no-flag 支持反向布尔选项;另有公开的 CommandErrors 错误集。README 补了单文件快速上手示例,展示根命令初始化、执行、选项与子命令的完整写法,包元数据也标明 .minimumzigversion。
Spinner 修了三个实际问题:停止或释放后光标能正确恢复显示;刷新速率不再把纳秒当毫秒,stop 不会再卡死在等待线程上;重复启动、更新消息和空帧集的生命周期更稳。printVersion 之后会 flush writer,版本输出不再被吞掉。
v5.0.02026-04-25
zli v5.0.0:这次版本号跳到大版本,主要是一次针对 Zig 0.16.0 的文档与示例修缮。README 里的示例代码此前有几处已经跟不上新版 API:内建函数的访问方式、writer 刷新、命令版本元数据的写法、reader 的接线方式都不太对,照抄会直接编译不过或行为异常,现已全部更正。另外,仓库里过时的 docs.md 引用被移除,统一指向在线文档 https://xcaeser.github.io/zli/ ,查阅起来更方便。如果你正从 Zig 0.15 系升级,建议先对照新 README 核对一下自己项目里对 zli 的用法,尤其是 writer 刷新和 reader 接线这两处,容易踩坑。完整变更见 https://github.com/xcaeser/zli/compare/v4.3.0...v5.0.0 。