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

Bash completion for subcommand flags #87

Merged
merged 14 commits into from
Jun 14, 2022
Merged

Conversation

mabelzhang
Copy link
Contributor

@mabelzhang mabelzhang commented Apr 30, 2022

🎉 New feature

Part of #1
Test with any or all of these subcommands (ign --commands shows these 11):

Summary

Demonstration of tab completion for ign-gui (libraries, Ruby parsing) and ign-plugin (executables, CLI11 parsing).
When we are happy with these two, it is easy to extend to other ign-* libraries.

Doing tab completion this way means it's purely at the bash interaction level, independent of how the actual flags are parsed and executed. Regardless of whether the flag implementation is Ruby or CLI11, the tab completion happens before any of those are incurred. gui and plugin are chosen so that we validate that here.

I took the liberty of adding comments to the existing code, because it took me a long time to understand even with online tutorials, this being my first time writing a bash completion script. Thought the comments might help the next person.

This set of PRs is for functionality, and the bash scripts are manually sourced for now.
The scripts will need to be installed for tab completion to happen out of the box, which is more about infrastructure and will be in a separate PR.

Test it

1efb619 installs a single script to source everything:

. install/share/gz/gz.completion

Then you should get tab completion when you type ign <subcommand> -<tab>. See those PRs for sample outputs.

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

@mabelzhang mabelzhang added the OOBE 📦✨ Out-of-box experience label Apr 30, 2022
@mabelzhang mabelzhang added this to Inbox in Core development via automation Apr 30, 2022
@github-actions github-actions bot added 🏯 fortress Ignition Fortress 🏰 citadel Ignition Citadel labels Apr 30, 2022
@mabelzhang mabelzhang moved this from Inbox to In review in Core development Apr 30, 2022
Signed-off-by: Mabel Zhang <[email protected]>
@mabelzhang
Copy link
Contributor Author

Do not merge this PR until we have a PR to install all the scripts and source them at once. Otherwise, this script will be calling functions that don't exist. This script is already being installed, so the new changes will probably break the original tab completion.

The other two PRs can be merged, as those scripts are new and not being used anywhere else.

Signed-off-by: Mabel Zhang <[email protected]>
@mabelzhang
Copy link
Contributor Author

mabelzhang commented May 3, 2022

1efb619 adds installation, which is also added to the ign-gui and ign-plugin PRs.
Let me know if it's better to break off installation into separate PRs (it would be another set of 3 PRs, 1 in each repo).

Scripts are installed to the directory install/share/ignition/ignition.completion.d/, which are sourced by the script installed at install/share/ignition/ignition.completion.
The user needs to source it manually:

. install/share/ignition/ignition.completion

I don't know if the way I've written this script is the most secure way to source bash scripts. What if somebody adds a random script matching the name pattern to that directory?
I think it probably needs to be versioned too, like the Ruby scripts? If one version of a library adds a new flag, then the bash script will need to have that new flag just for that version.
If that turns out to be complicated, maybe it's better to break off installation into separate PRs to figure those things out.

Either way, this is probably still not compatible with https://github.com/ignition-release/ign-tools-release/pull/4/files . I think bash completion requires a single file. We probably still have to pipe all the repos' individual scripts to a single script before installing to /usr/share/bash-completion/completions/ign.

etc/CMakeLists.txt Outdated Show resolved Hide resolved
etc/ign.bash_completion.sh Outdated Show resolved Hide resolved
etc/CMakeLists.txt Outdated Show resolved Hide resolved
@j-rivero j-rivero removed this from In review in Core development May 6, 2022
@chapulina chapulina added this to Inbox in Core development via automation May 14, 2022
@chapulina chapulina moved this from Inbox to In review in Core development May 14, 2022
@mabelzhang
Copy link
Contributor Author

mabelzhang commented May 20, 2022

To push this along before I'm gone next week, I've started opening PRs in more repos, following the installation method in this comment #87 (comment) that worked for gui and plugin.

@mabelzhang mabelzhang changed the title Bash completion for subcommand flags (gui and plugin) Bash completion for subcommand flags May 20, 2022
etc/gz.completion Show resolved Hide resolved
etc/ign.bash_completion.sh Show resolved Hide resolved
Copy link
Contributor

@chapulina chapulina left a comment

Choose a reason for hiding this comment

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

Just one last thing

etc/CMakeLists.txt Show resolved Hide resolved
etc/CMakeLists.txt Outdated Show resolved Hide resolved
@mabelzhang
Copy link
Contributor Author

All PRs have now been opened for second-level flags.
All ready for another pass. The main change is that the flags are no longer hard coded in the tests.

@chapulina chapulina dismissed ahcorde’s stale review June 7, 2022 16:09

Comments addressed

@chapulina chapulina merged commit 9881cd0 into ign-tools1 Jun 14, 2022
@chapulina chapulina deleted the mabelzhang/subcommands branch June 14, 2022 21:50
Core development automation moved this from In review to Done Jun 14, 2022
@chapulina chapulina moved this from Done to Highlights in Core development Jun 16, 2022
@scpeters
Copy link
Member

I noticed the nightly builds are unstable since this was merged forward since the newly installed completion files are not handled by the current debian metadata

we should update the release repos for tools1 and tools2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏰 citadel Ignition Citadel 🏯 fortress Ignition Fortress OOBE 📦✨ Out-of-box experience
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

4 participants