Skip to content

Conversation

@fischeti
Copy link
Contributor

@fischeti fischeti commented Jan 5, 2026

CLI refactor

derive feature

Since a while clap supports declaritive structs instead of a runtime builder, which is now the recommended way to build CLIs. It is easier to read, and modify and the resulting implementation is very clean in my opinion. Especially when it comes to subcommands which are represented as enums in Rust.

CLI organisation

I reorganized all the CLI subcommands and flags, in a way that should still be backwards compatible:

  • Script targets i.e. bender script <target> are now implemented as nested subcommands of script. This change is mainly reflected when calling the help page of script.
  • Some of the script targets where previously defined as global but were not used by all targets and had to be checked inside script.rs. Examples are --vlog-arg, --vcom-arg and --only-*. Now, they are moved/duplicated into each target that uses them which automatically takes care of these checks
  • Some flags have been renamed i.e. --vlog-arg was used by all targets for general verilog arguments even though the underlying executable has a different name. Now, the flag is called --vlogan-arg for VCS, but backward compatibility is ensured with aliases to --vlog-arg.
  • The help pages are now colored and the flags are now grouped into global options and subcommand specific options (+ subsubcommand options for bender script <target> --help).
  • Several aliases were introduced, which do not show up on help pages but are compatible. Those mainly consist of the plural/singular version of the flag e.g. --vlog-args/--vlog-arg both work now or parents/parent as well.

Environment variables

Global flags (e.g. git throttle, local, dir etc., ) can now also be provided as environment variables. The help pages also reflect this. The precedence is flag > environment variable > default.

Tests

I added an extensive test suite cli_regression, that checks the script output of the new CLI against the old one i.e. it installs a secondary bender binary from the master branch and diffs the two outputs.

TODOs:

  • Fix plugins (or deprecate them?)
  • Remove comments after review (of previous CLI command builders)
  • Evaluate further optimizations (e.g. bender script <target> could be implemented as subsubcommands with enums instead of strings if possible)
  • Remove redundant $[arg(long = <field-but-dashed>, short = <first-letter-of-field>]
  • Potentially deprecate modify previous --vcom-args etc., in favor of tool-specific args (with graceful deprecation warning in the beginning) with aliases to keep backward compability
  • Consider using env feature of clap to set flags based on environment variables (and deprecate config?)
  • Fix Windows tests (or not?). Currently there is an inconsistency with new line delimiters.
  • Review of consisteny between old CLI and new one ensure backward compability
  • Decide how/whether to merge cli_regression test suite
  • Change flag and add backward compatible aliases for flags that used lower_case i.e. vendor had some.
  • Address all inline TODOs

@fischeti fischeti changed the title Refactor cli to use derive feature of clap Refactor CLI to use derive feature of clap Jan 5, 2026
@fischeti fischeti force-pushed the fischeti/cli-derive branch from 430cc9e to 5f1b355 Compare January 6, 2026 00:03
@fischeti fischeti force-pushed the fischeti/cli-derive branch from 41a033a to 8a6b118 Compare January 6, 2026 18:39
@fischeti fischeti changed the title Refactor CLI to use derive feature of clap Refactor CLI, group flags, add aliases and support for env variables Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants