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

lib/utilities: refactor _bash-it-pluralize-component() & other improvements #1999

Merged
merged 5 commits into from
Jan 18, 2022

Conversation

gaelicWizard
Copy link
Contributor

@gaelicWizard gaelicWizard commented Dec 27, 2021

Please review commit notes as appropriate.

Description

  • Refactor function _bash-it-pluralize-component();
  • Remove dependencies from _bash-it-component-item-is-enabled() (so it's much faster);
  • Fix _bash-it-component-help() for long component names;
  • Clean up tests a little.

Motivation and Context

Refactoring _bash-it-pluralize-component() started by accident while fiddling with bash-it search and resulted in:

  • renaming the function so it better matches it's siblings,
  • adding a matching _bash-it-component-singularize() which can be used when logging and other places,
  • using printf's -v flag to store to a variable, rather than echoing to stdout to reduce subshells,
  • updating _bash-it-component-cache-file() and _bash-it-component-help() to use the variable,
  • updating _bash-it-component-cache-file() to use printf -v too.

Alsö, misc fixes to lib/utilities that came along with the branch and deobfuscation of tests/utilities.

How Has This Been Tested?

These fixes have long been part of my main branch and my shellcheck branch(es), and all automated tests pass.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • If my change requires a change to the documentation, I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • If I have added a new file, I also added it to clean_files.txt and formatted it using lint_clean_files.sh.
  • I have added tests to cover my changes, and all the new and existing tests pass.

@gaelicWizard gaelicWizard force-pushed the utilities branch 5 times, most recently from f592e64 to 8842ff1 Compare December 27, 2021 22:05
@gaelicWizard gaelicWizard changed the title Utilities: fixes & improvements Utilities: refactor _bash-it-pluralize-component() & other improvements Dec 27, 2021
@gaelicWizard gaelicWizard marked this pull request as ready for review December 27, 2021 22:14
@gaelicWizard gaelicWizard marked this pull request as draft December 28, 2021 20:55
@gaelicWizard gaelicWizard force-pushed the utilities branch 3 times, most recently from 8ea16b7 to a72c04e Compare December 29, 2021 07:06
@gaelicWizard gaelicWizard marked this pull request as ready for review December 29, 2021 07:07
@gaelicWizard gaelicWizard force-pushed the utilities branch 3 times, most recently from 670ddbf to de71edc Compare January 2, 2022 01:48
@gaelicWizard
Copy link
Contributor Author

@tsiflimagas, want to take a look at this one too? 😆

@gaelicWizard gaelicWizard changed the title Utilities: refactor _bash-it-pluralize-component() & other improvements lib/utilities: refactor _bash-it-pluralize-component() & other improvements Jan 2, 2022
Copy link
Member

@NoahGorny NoahGorny left a comment

Choose a reason for hiding this comment

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

we can merge this after #2002

@gaelicWizard gaelicWizard force-pushed the utilities branch 2 times, most recently from 268f994 to ed3bea6 Compare January 8, 2022 16:24
@gaelicWizard
Copy link
Contributor Author

we can merge this after #2002

@NoahGorny, I don't think any of this depends on my BATS branch

Make `_bash-it-component-item-is-enabled()` operate *without* using `_bash-it-component-help()`...so it's now *much* faster.
Alsö, minor tweak to `_bash-it-array-contains-element()` for clarity.

This fixes Bash-it#1978.
Fix up and rename `_bash-it-pluralize-component()` to `_bash-it-component-pluralize()`, and add matching function `_bash-it-component-singularize()`.
Match idiom of `_bash-it-component-singularize()`
Don't use `local -n var` so that we can support v3.2...

Note: function names and variable names are different namespaces, so we can have a variable named the same as the function...which makes it really easy to predict default names for results when returning this way.
@NoahGorny NoahGorny merged commit 8d5d907 into Bash-it:master Jan 18, 2022
@gaelicWizard gaelicWizard deleted the utilities branch January 18, 2022 17:46
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