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

scripts: streamline 'printf' usage and consequently use a format string #2564

Merged
merged 5 commits into from
May 5, 2022

Conversation

casperklein
Copy link
Member

@casperklein casperklein commented Apr 27, 2022

Description

This PR streamlines the printf usage and consequently uses a format string. This (best) practice also avoids possible problems with strings containing special characters like %s, \n etc.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (non-breaking change that does improve existing functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (README.md or the documentation under docs/)
  • If necessary I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@casperklein casperklein added area/scripts kind/improvement Improve an existing feature, configuration file or the documentation labels Apr 27, 2022
@casperklein casperklein added this to the v11.1.0 milestone Apr 27, 2022
@casperklein casperklein requested a review from a team April 27, 2022 17:22
@casperklein casperklein self-assigned this Apr 27, 2022
@casperklein casperklein changed the title Streamline printf usage and consequently use a format string Streamline 'printf' usage and consequently use a format string Apr 27, 2022
@casperklein casperklein marked this pull request as draft April 27, 2022 17:23
@casperklein
Copy link
Member Author

Converting this

printf "\e[35mADDALIAS\e[31m(\e[93m8\e[31m)

to

printf '%s' "\e[35mADDALIAS\e[31m(\e[93m8\e[31m)

does not work. \e[35m will not be evaluated as the color purple.

All scripts already source helpers/index.sh. I think it's the best, to centrally define all colors and then just use them as vars.
There is already something like this here:

LOG_RESET='\e[0m'
LOG_LGRAY='\e[37m'
LOG_LBLUE='\e[94m'
LOG_BLUE='\e[34m'
LOG_LYELLOW='\e[93m'
LOG_RED='\e[91m'

But not all colors are covered there + variable names refer to log stuff.

I propose to:

  1. add missing colors
  2. change variable names to something more general like $RED or $COLOR_RED instead of $LOG_RED.
  3. and use these variables in other scripts.

If there is consensus, I'll take care of this in a separate PR and adjust this PR afterwards.

@georglauterbach
Copy link
Member

I propose to:

  1. add missing colors
  2. change variable names to something more general like $RED or $COLOR_RED instead of $LOG_RED.
  3. and use these variables in other scripts.

If there is consensus, I'll take care of this in a separate PR and adjust this PR afterwards.

Sounds very good to me - I’m all for it 👍🏼

@casperklein casperklein marked this pull request as ready for review April 28, 2022 00:45
@casperklein casperklein merged commit 2977cb6 into docker-mailserver:master May 5, 2022
@casperklein casperklein deleted the printf branch May 5, 2022 15:48
@georglauterbach georglauterbach changed the title Streamline 'printf' usage and consequently use a format string scripts: streamline 'printf' usage and consequently use a format string May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/scripts kind/improvement Improve an existing feature, configuration file or the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants