Skip to content

Improve Shell Completion#2845

Open
skusel wants to merge 5 commits intof3d-app:masterfrom
skusel:JsonCliOptions
Open

Improve Shell Completion#2845
skusel wants to merge 5 commits intof3d-app:masterfrom
skusel:JsonCliOptions

Conversation

@skusel
Copy link
Contributor

@skusel skusel commented Feb 3, 2026

Describe your changes

The goal of this change is to improve shell completion by making the shell completion scripts more reliable.

I moved CLI option definitions from the source code to cli-options.json in the resources directory. I also added a cli-options.schema.json file so users with an editor that supports JSON schema diagnostics can take advantage of the warnings. A GitHub workflow step was also added to validate cli-options.json using the schema file.

cli-options.json is used to generate F3DCLIOptions.h, completion.bash, completion.fish, and completion.zsh during the CMake configuration step. Any updates to cli-options.json cause CMake to rerun configuration.

The bulk of the work is done in f3dCLIOptions.cmake.

The completion files have been tested against all three shells.

Many existing tests exercise CLI options. I added one additional TestHelp* check, but I believe the CLI options changes are already well covered by the existing tests.

Issue ticket number and link if any

#2121

Checklist for finalizing the PR

  • I have performed a self-review of my code
  • I have added tests for new features and bugfixes
  • I have added documentation for new features
  • If it is a modifying the libf3d API, I have updated bindings
  • If it is a modifying the .github/workflows/versions.json, I have updated docker_timestamp

Continuous integration

Please write a comment to run CI, eg: \ci fast.
See here for more info.

@skusel
Copy link
Contributor Author

skusel commented Feb 3, 2026

\ci fast

@skusel skusel force-pushed the JsonCliOptions branch 2 times, most recently from 86a716d to 03b77fb Compare February 3, 2026 00:37
@snoyer
Copy link
Contributor

snoyer commented Feb 3, 2026

Would it be preferable to use the json file at build-time instead of run-time?

  1. for the app that would mean either:
  • generating the current static inline const std::array<CLIGroup, ...> CLIOptions = {{ lists but from the json instead of written by hand
  • generating hardcoded/unrolled cxxopts code directly
  1. for the completion files it would mean baking into the scripts whatever strings/commands this PR concatenates together at run-time with python (and then you have only a single hardcoded code path that replaces both the python3 and the _parse_help/grep/sed cases)

However before looking into it too hard I think there's a question about the implications of parsing a json file vs parsing the --help text:

  • There are a few options that are behind #ifdef guards, meaning the completion may offer options that are not actually in the binary the user has (unless you somehow drag these condition over to the user and emulate the checks in the completion scripts?)
    That could be addressed by generating the completion strings/commands at build-time making sure to apply the same guards
  • I haven't checked if that's actually the case but do we have options that are guarded at run-time? like with env vars or something?
    Because in that case using the binary as the only source of truth, whether it's parsing the help text or adding a dedicated way to generate completions, may be the only solution (short of duplicating the app's logic in the completion scripts)

@mwestphal mwestphal self-requested a review February 3, 2026 06:53
@mwestphal
Copy link
Member

python to parse json is a no-go, and indeed, better to parse at compile time, like we do with options.json.

Copy link
Member

@mwestphal mwestphal left a comment

Choose a reason for hiding this comment

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

Im afraid design needs to be discussed.

@skusel skusel requested a review from mwestphal February 4, 2026 03:07
@skusel skusel force-pushed the JsonCliOptions branch 2 times, most recently from e9b5dac to 79a15c2 Compare February 4, 2026 03:31
Copy link
Member

@mwestphal mwestphal left a comment

Choose a reason for hiding this comment

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

remove all unrelated style changes.

skusel added a commit to skusel/f3d that referenced this pull request Feb 4, 2026
skusel added a commit to skusel/f3d that referenced this pull request Feb 4, 2026
skusel added a commit to skusel/f3d that referenced this pull request Feb 4, 2026
skusel added a commit to skusel/f3d that referenced this pull request Feb 5, 2026
@skusel
Copy link
Contributor Author

skusel commented Feb 5, 2026

remove all unrelated style changes.

I believe you are referring to the stylistic changes made to application/F3DOptionsTools.cxx. These are needed for the formatting checks workflow to complete. Previously, buried in the CLIOptions array initialization, there was a clang-format off comment and no matching clang-format on comment. This disabled clang formatting for the majority of the application/F3DOptionsTools.cxx file. Now that the clang-format off comment has been removed, clang-format caught a bunch of formatting errors.

@skusel skusel requested a review from mwestphal February 5, 2026 00:23
@mwestphal
Copy link
Member

remove all unrelated style changes.

I believe you are referring to the stylistic changes made to application/F3DOptionsTools.cxx. These are needed for the formatting checks workflow to complete. Previously, buried in the CLIOptions array initialization, there was a clang-format off comment and no matching clang-format on comment. This disabled clang formatting for the majority of the application/F3DOptionsTools.cxx file. Now that the clang-format off comment has been removed, clang-format caught a bunch of formatting errors.

You are absolutely right! Do you think you could put these changes in a separate commit (or even PR) ?

skusel added a commit to skusel/f3d that referenced this pull request Feb 5, 2026
skusel added a commit to skusel/f3d that referenced this pull request Feb 5, 2026
skusel added a commit to skusel/f3d that referenced this pull request Feb 5, 2026
@skusel skusel requested review from Meakk, mwestphal and snoyer February 6, 2026 00:28
Copy link
Member

@mwestphal mwestphal left a comment

Choose a reason for hiding this comment

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

changes and suggestions

skusel added a commit to skusel/f3d that referenced this pull request Feb 6, 2026
skusel added a commit to skusel/f3d that referenced this pull request Feb 6, 2026
@skusel skusel requested a review from mwestphal February 6, 2026 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants