I extracted and updated Tigerbeetle's argument parser

argparser


Repo: https://codeberg.org/zmitchell/argparser

Not a ton to see here because it’s mostly a copy-paste-edit job, but I’m posting in case anyone else has wanted this. I like the philosophy of the argument parser in Tigerbeetle’s repository and wanted to use it in some of my projects, so I copied it out of their repo and made it slightly friendlier to use for other projects (e.g. doesn’t depend on stdx.zig or snaptest.zig from their repository).

The README contains a full list of changes compared to the upstream parser, but the highlights are:

  • Updated for Zig 0.16.0
  • Doesn’t exit on error
  • Naming follows Zig conventions (e.g. camel case for function names)
  • ohsnap for snapshot testing (thank you @mnemnion)

There’s a full description in the README, but the short version of what sets this argument parser apart is:

  • Long arguments only (e.g. --foo, not -f).
    • -h / --help is an exception
  • --foo=bar, not --foo bar.
  • Handwritten help text instead of generating it from comments.

Supported Zig versions

Zig 0.16.0

(No AI usage, for the record. All bugs, typos, etc were lovingly handcrafted.)

14 Likes

@mnemnion I’m not sure if I had incorrect expectations about the default pretty options, but there are a couple of cases where strings get printed as arrays of decimal values or they’re omitted:

Some examples: