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.
  • The --only-* flags are grouped, meaning clap will automatically return an error if multiple one of them are specified at the same time. The same goes for packages --graph, that does not allow --version and/or --targets
  • 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.

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. Fixed in CLI regression tests #245
  • Decide how/whether to merge cli_regression test suite moved to CLI regression tests #245
  • Change flag and add backward compatible aliases for flags that used lower_case i.e. vendor had some.
  • Address all inline TODOs
  • Review of consisteny between old CLI and new one ensure backward compability
  • Wait for CLI regression tests #245 to be merged

@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 2 times, most recently 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
@fischeti fischeti force-pushed the fischeti/cli-derive branch from db38116 to 216dcad Compare January 9, 2026 21:19
@fischeti fischeti marked this pull request as ready for review January 10, 2026 14:46
@fischeti fischeti mentioned this pull request Jan 12, 2026
1 task
@fischeti fischeti force-pushed the fischeti/cli-derive branch from 216dcad to bf61e49 Compare January 12, 2026 17:59
@fischeti fischeti force-pushed the fischeti/cli-derive branch from 6b73dae to 17ec92f Compare January 13, 2026 15:21
Copy link
Member

@micprog micprog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the additions! I really like the new format and what it enables in code cleanliness, as well as the predefined environment variables for certain flags. I haven't gone through the script.rs file yet, but here is some initial feedback.

@micprog
Copy link
Member

micprog commented Jan 13, 2026

The script command looks OK at first glance, I think testing through usage will reveal any issues here. The CLI regression tests failures also look as expected.

The default of `clap` is to set the `bool` to `false` so specifying this
action doesn't do anything expect making the derive macro longer
@fischeti
Copy link
Contributor Author

fischeti commented Jan 13, 2026

Thanks for the review and catching some errors that I missed! I should have addressed all of your comments. There are currently three CLI tests failing which is expected:

    cli_synopsys_verilog_arg
    cli_synopsys_vhdl_arg
    cli_verilator_args

Those are "new" argument names that didn't exist before (but with backward compatible aliases that are also checked with in the *_old_* tests).

The one that I don't really know what to do about is the cli_template_json. It is kind of expected that it fails, because it does not contain some arguments anymore that were previously global to script.

Copy link
Member

@micprog micprog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@micprog micprog merged commit 30ec37c into master Jan 14, 2026
7 of 9 checks passed
@micprog micprog deleted the fischeti/cli-derive branch January 14, 2026 12:54
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