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

Use getops #561

Merged
merged 36 commits into from Feb 6, 2019
Merged

Use getops #561

merged 36 commits into from Feb 6, 2019

Conversation

maniackcrudelis
Copy link
Contributor

@maniackcrudelis maniackcrudelis commented Oct 16, 2018

The problem

getopts is now available for all our official helpers

Solution

Migrate all our helpers to getopts

PR Status

  • ynh_use_logrotate: Fully tested (mainly because it was a specific case)
  • ynh_add_systemd_config: Legacy mode ?? | getopts mode ??
  • ynh_remove_systemd_config: Legacy mode ?? | getopts mode ??
  • ynh_backup: Legacy mode OK | getopts mode OK
  • ynh_restore_file: Legacy mode OK | getopts mode OK
  • ynh_store_file_checksum: Legacy mode OK | getopts mode OK
  • ynh_backup_if_checksum_is_different: Legacy mode OK | getopts mode OK
  • ynh_delete_file_checksum: Already done
  • ynh_secure_remove: Legacy mode OK | getopts mode OK
  • ynh_validate_ip: Legacy mode ?? | getopts mode ??
  • ynh_validate_ip4: Legacy mode ?? | getopts mode ??
  • ynh_validate_ip6: Legacy mode ?? | getopts mode ??
  • ynh_mysql_connect_as: Legacy mode OK | getopts mode OK
  • ynh_mysql_execute_as_root: Legacy mode OK | getopts mode OK
  • ynh_mysql_execute_file_as_root: Legacy mode ?? | getopts mode ??
  • ynh_mysql_dump_db: Legacy mode OK | getopts mode OK
  • ynh_mysql_user_exists: Legacy mode ?? | getopts mode OK
  • ynh_mysql_setup_db: Legacy mode OK | getopts mode OK
  • ynh_mysql_remove_db: Legacy mode OK | getopts mode OK
  • ynh_sanitize_dbid: Legacy mode OK | getopts mode OK
  • ynh_normalize_url_path: Legacy mode OK | getopts mode OK
  • ynh_find_port: Legacy mode ?? | getopts mode ??
  • ynh_webpath_available: Legacy mode OK | getopts mode OK
  • ynh_webpath_register: Legacy mode OK | getopts mode OK
  • ynh_install_nodejs: Legacy mode ?? | getopts mode ??
  • ynh_package_is_installed: Legacy mode ?? | getopts mode ??
  • ynh_package_version: Legacy mode ?? | getopts mode ??
  • ynh_die: Legacy mode ?? | getopts mode OK
  • ynh_print_info: Legacy mode ?? | getopts mode ??
  • ynh_print_warn: Legacy mode ?? | getopts mode ??
  • ynh_print_err: Legacy mode ?? | getopts mode ??
  • ynh_app_setting_get: Legacy mode OK | getopts mode OK
  • ynh_app_setting_set: Legacy mode OK | getopts mode OK
  • ynh_app_setting_delete: Legacy mode OK | getopts mode OK
  • ynh_string_random: Legacy mode ?? | getopts mode OK
  • ynh_replace_string: Legacy mode OK | getopts mode OK
  • ynh_replace_special_string: Legacy mode ?? | getopts mode ??
  • ynh_user_exists: Legacy mode ?? | getopts mode ??
  • ynh_user_get_info: Legacy mode ?? | getopts mode ??
  • ynh_system_user_exists: Legacy mode ?? | getopts mode OK
  • ynh_system_user_create: Legacy mode OK | getopts mode OK
  • ynh_system_user_delete: Legacy mode OK | getopts mode OK
  • ynh_setup_source: Legacy mode OK | getopts mode OK

How to test

Although it's not finished, I'm not going to go back unless there's an error to fix.
So don't hesitate to help by testing the helpers.

To test, replace the official helpers by this version. (/usr/share/yunohost/helpers.d/)

Validation

  • Principle agreement 0/2 :
  • Quick review 0/1 :
  • Simple test 0/1 :
  • Deep review 0/1 :

@alexAubin alexAubin added this to the 3.x milestone Oct 24, 2018
@alexAubin alexAubin added this to the 3.5.x milestone Dec 29, 2018
@maniackcrudelis
Copy link
Contributor Author

maniackcrudelis commented Dec 31, 2018

I tried to test with a full replacement of the helpers.
Tried with wordpress directly, which isn't using getopts args.
So, getopts is used in Legacy mode , whith many weird errors...

Here my errors so far, for those who want to try as well.

@maniackcrudelis
Copy link
Contributor Author

Finally found the error with mysql, and that's bigger than I thought it would be...
An associative array isn't sorted like a indexed one is. Which means that we can't know in which order the array will be stored.

In ynh_mysql_setup_db, the array is set that way:

declare -Ar args_array=( [u]=db_user= [n]=db_name= [p]=db_password= )

Most of the time, for other helpers, the array will be set as:

[ u ] - [db_user=]
[ n ] - [db_name=]
[ p ] - [db_password=]

But, during my tests, the array is set that way

[ n ] - [db_name=]
[ p ] - [db_password=]
[ u ] - [db_user=]

That's not a problem when using getopts parameters, because we're using the key, n, p or u to access the array. But, when using the legacy mode, there's no way to know which argument is supposed to match which option, unless by using arguments in the same order than the array.
For this example, we assume that $1 is db_user, $2 db_name and $3 db_password. But when the array isn't sorted the same way than the line that create it. How can we know which option was the first one, and so on.

This issue will need to rethink a part of the legacy mode, and also to add a variable in the helper that call ynh_handle_getopts_args to fix that order in a strict way.

There's no reason in that loop where we're looking for values of an option to have a blank cell in the array of arguments. Unless for an option with a missing value.
In that case, it's better to ignore this condition and store a blank value in the variable.
Otherwise, in case of missing value for an option, with this condition, we enter in an infinite loop, because the shift will stay at 0.
@maniackcrudelis
Copy link
Contributor Author

I guess now the code is stable enough to really starting to test the helpers...

Many core backup script source /usr/share/yunohost/helpers.d/filesystem only. Not sure it's a wonderful idea...
@maniackcrudelis
Copy link
Contributor Author

I've tested most of the helpers with an app and package check, without any errors.
Some aren't tested yet, feel free to do it if you want. I do not expect any errors either.
For me this PR is finally ready to be reviewed.

@maniackcrudelis
Copy link
Contributor Author

#455 has been merged in unstable a few hours ago.
This implementation of getopts needs the fix of ynh_handle_getopts_args, currently in this PR.

So, please this PR needs reviews.

@alexAubin
Copy link
Member

Uh I didn't realize that ... Maybe we can revert and reopen #455 then ? Or merge only the new getopts file from this PR ... I'm a bit unconfortable with merging all this PR considering the number of changes and that the goal is to go for a stable on ~Tuesday

@maniackcrudelis
Copy link
Contributor Author

I'll make another PR to fix ynh_handle_getopts_args then.
After the stable release though, I would be interesting to merge this one. So we would have some test with it.

@alexAubin
Copy link
Member

Yup, same 👍

@maniackcrudelis
Copy link
Contributor Author

@YunoHost/apps

@alexAubin
Copy link
Member

So do we agree to merge this as is to run tests via the C.I ? 😉

@JimboJoe
Copy link
Member

JimboJoe commented Feb 5, 2019

This is a great piece of work, and while I haven't tested it myself, it's totally LGTM! 👍

Copy link
Member

@JimboJoe JimboJoe left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@maniackcrudelis
Copy link
Contributor Author

So do we agree to merge this as is to run tests via the C.I ?

Yep, would be great !
At least for unstable test to begin.

@alexAubin alexAubin merged commit 69a896e into stretch-unstable Feb 6, 2019
@alexAubin alexAubin deleted the use_getops branch February 6, 2019 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants