Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cmd,cli): In-house CLI library to replace zig-cli #570

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

InKryption
Copy link
Contributor

This introduces a CLI library developed in my spare time.
Some features to highlight:

  • Data in & data out: unlike zig-cli, it isn't the executor, it simply parses a list of strings (typically argv[1..]), and returns a struct type specified by the caller, using normal fields to represent options, and subcommands as nested tagged unions.
  • No global state: because it's data in & data out, no global state is required to share data between sub-commands.
  • Statically verified: unlike zig-cli, there are no potential runtime bugs from an ill-defined command definition, all validation occurs at compile time with (mostly) informative error messages, and exhaustively specified associations.
  • Easy sharing of options & groups of options across subcommands, with high capacity for unifying relevant information.
  • Automatic help command output including default values, & automatically indented multiline help messages for options and sub-commands, with automatic tty support:
    image

As a demo, this PR also adds some adjacent improvements to the cmd.zig code, such as removing the global variables, refactoring some of the help messages, and also happens to re-organize some of the options in certain ways that seemed slightly more logical.

There are more improvements that can be made to cmd.zig, in particular replacing much of config.Cmd with the newly-introduced option groups.

The cli.zig code is not totally perfect - it is perhaps a bit more complicated than need be, and it's not super obvious at a glance how different parts of the code flow into each other. I intend to simplify and improve these things, but the actual API should remain relatively the same.

@InKryption InKryption self-assigned this Feb 18, 2025
@InKryption InKryption force-pushed the ink/better-cli branch 3 times, most recently from 0da5f2f to d09d113 Compare February 19, 2025 00:34
Copy link

codecov bot commented Feb 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

also remove zig-cli import from sig/cmd.zig
Extract cli.zig out into a separate module, to more easily share
between main exe and geyser reader exe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

1 participant