Added Magento2 CLI completions#4043
Conversation
This is the completion file for the Magento2 CLI application I use on my servers. It has an additional feature tho, I'm not sure if it fits into the fish completion philosophy: If you provide limited access credentials, it will connect to the MySQL database and provide additional suggestions, such as available users, themes or indexers in the database. If this file is never touched, those suggestions simply won't show up. I, personally, find them to be pretty useful, though. Should I remove those database suggestions before creating a PR?
Yes, please. Approximately one person (i.e. you) is going to use that, so the code will just rot. I'll add other comments inline. |
| ################################################ | ||
|
|
||
| set -l result (mysql -u{$fish_mysql_user} -p{$fish_mysql_pass} -e $argv --skip-column-names 2>&1 | grep -v "mysql:") | ||
| if [ (echo $result | grep ERROR) ] |
There was a problem hiding this comment.
As a general comment (this will be remove later):
-
We prefer
string matchfor this since it doesn't require forking off an external process -
The test is unnecessary since both grep and
string matchhave a "-q" option that silences output and returns 0 if there are matches, 1 if there are none.
So this would be if string match -qr 'ERROR' -- $result or if echo $result | grep -q ERROR.
|
|
||
| function __fish_print_magento_url_protocols -d "Shows all available URL protocols" | ||
| echo http://\t"HTTP" | ||
| echo https://\t"HTTPS" |
There was a problem hiding this comment.
In general, if suggestions just duplicate information you can already see we prefer leaving them. So this would just echo "http://" and "https://".
| set -l users (__fish_print_magento_mysql_command 'select user from mysql.user;' | sort -u) | ||
|
|
||
| for i in $users | ||
| echo $i\t"$i" |
There was a problem hiding this comment.
Like above, these descriptions are completely useless.
So this entire loop can just be printf '%s\n' $users. Alternatively, just let the output of the above command substitution go out.
| # Retrieves all available MySQL users | ||
| ### | ||
| function __fish_print_magento_mysql_users -d "Shows all available MySQL users" | ||
| set -l users (__fish_print_magento_mysql_command 'select user from mysql.user;' | sort -u) |
There was a problem hiding this comment.
Sorting and removing duplicates is something fish already does, so you can leave off the sort -u.
| set -l modules (magento module:status) | ||
|
|
||
| for i in $test | ||
| if [ (echo $i) -a (echo $i) != 'None' ] |
There was a problem hiding this comment.
The echos here are useless. if test -n "$i" -a "$i" != "None".
| # | ||
| # maintenance:disable | ||
| # | ||
| __fish_magento_register_command_option maintenance:disable -l ip -d "Allowed IP addresses (use 'none' to clear allowed IP list) (multiple values allowed)"; |
There was a problem hiding this comment.
Because of the plural, it already sounds like multiple values are okay.
There was a problem hiding this comment.
Taken from the original help output.
| # | ||
| # cache:clean | ||
| # | ||
| __fish_magento_register_command_option cache:clean -f -a "(__fish_print_magento_cache_types)" -d "Space-separated list of cache types or omit to apply to all cache types."; |
There was a problem hiding this comment.
Taken from the original help output.
| # | ||
| # admin:user:create | ||
| # | ||
| __fish_magento_register_command_option admin:user:create -f -r -l admin-user -d "(Required) Admin user"; |
There was a problem hiding this comment.
Since these are required, it would be great if we could just automatically suggest them. That currently doesn't happen with options, so you'll have to suggest one via "-a".
So that would be
# Force suggesting options
__fish_magento_register_command_option admin:user:create -a '--admin-user'There was a problem hiding this comment.
(Note: Ideally you'd suggest only the ones that haven't been given yet. See __fish_contains_opt)
There was a problem hiding this comment.
Fixed. I have a question though: Is it possible to indicate a parameter needs a value? Magento requires parameter values as --param="value", but I haven't found a way to insert the equals sign yet..
| # | ||
| # list | ||
| # | ||
| __fish_magento_register_command_option list -f -l xml -d "To output list as XML"; |
There was a problem hiding this comment.
Taken from the original help output.
| complete -x -c magento -o -vv; | ||
| complete -x -c magento -o vvv; | ||
| complete -x -c magento -s V -l version -d "Display this application version"; | ||
| complete -x -c magento -l ansi -d "Force ANSI output"; |
There was a problem hiding this comment.
I'm assuming the "ANSI" here refers to ANSI color codes? Then it should be "Force colored output".
There was a problem hiding this comment.
Same as above, taken from Magento help output
| # | ||
| # indexer:reindex | ||
| # | ||
| __fish_magento_register_command_option indexer:reindex -f -a "(__fish_print_magento_indexer_names)" -d 'Space-separated list of index types or omit to apply to all indexes.'; |
There was a problem hiding this comment.
You probably still want to complete these commands, even if you can't complete the arguments.
There was a problem hiding this comment.
Well they don't have any parameters, and I've registered the subcommand itself already, so that should be fine, shouldn't it?
There was a problem hiding this comment.
You have? Sorry, I must have missed that!
Tried to shorten the text as much as possible and removed unnecessary characters
|
Merged, thanks! @zanchey: This is good for 2.6.0. |
* Added Magento2 CLI completions This is the completion file for the Magento2 CLI application I use on my servers. It has an additional feature tho, I'm not sure if it fits into the fish completion philosophy: If you provide limited access credentials, it will connect to the MySQL database and provide additional suggestions, such as available users, themes or indexers in the database. If this file is never touched, those suggestions simply won't show up. I, personally, find them to be pretty useful, though. Should I remove those database suggestions before creating a PR? * Removed functions using MySQL, updated formatting * Several smaller fixes * Improved descriptions Tried to shorten the text as much as possible and removed unnecessary characters (cherry picked from commit 71f5fe1)
|
Thanks, taken for 2.6.0 as 291d88a. |
Description
This is the completion file for the Magento2 CLI application I use on my servers. It has an additional feature tho, I'm not sure if it fits into the fish completion philosophy:
If you provide limited access credentials, it will connect to the MySQL database and provide additional suggestions, such as available users, themes or indexers in the database. If this file is never touched, those suggestions simply won't show up. I, personally, find them to be pretty useful, though.
Should I remove those database suggestions before creating a PR?
Fixes issue #
TODOs: