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

Added Magento2 CLI completions #4043

Merged
merged 4 commits into from May 18, 2017
Merged

Conversation

@Radiergummi
Copy link
Contributor

@Radiergummi Radiergummi commented May 18, 2017

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:

  • Changes to fish usage are reflected in user documentation/manpages.
  • Tests have been added for regressions fixed
  • User-visible changes noted in CHANGELOG.md
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?
@faho
Copy link
Member

@faho faho commented May 18, 2017

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) ]

This comment has been minimized.

@faho

faho May 18, 2017
Member

As a general comment (this will be remove later):

  • We prefer string match for this since it doesn't require forking off an external process

  • The test is unnecessary since both grep and string match have 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"

This comment has been minimized.

@faho

faho May 18, 2017
Member

In general, if suggestions just duplicate information you can already see we prefer leaving them. So this would just echo "http://" and "https://".

This comment has been minimized.

@Radiergummi

Radiergummi May 18, 2017
Author Contributor

Fixed.

set -l users (__fish_print_magento_mysql_command 'select user from mysql.user;' | sort -u)

for i in $users
echo $i\t"$i"

This comment has been minimized.

@faho

faho May 18, 2017
Member

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)

This comment has been minimized.

@faho

faho May 18, 2017
Member

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' ]

This comment has been minimized.

@faho

faho May 18, 2017
Member

The echos here are useless. if test -n "$i" -a "$i" != "None".

This comment has been minimized.

@Radiergummi

Radiergummi May 18, 2017
Author Contributor

Fixed.

#
# 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)";

This comment has been minimized.

@faho

faho May 18, 2017
Member

Because of the plural, it already sounds like multiple values are okay.

This comment has been minimized.

@Radiergummi

Radiergummi May 18, 2017
Author Contributor

Taken from the original help output.

This comment has been minimized.

@Radiergummi

Radiergummi May 18, 2017
Author Contributor

Fixed.

#
# 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.";

This comment has been minimized.

@faho

faho May 18, 2017
Member

"... or omit for all".

This comment has been minimized.

@Radiergummi

Radiergummi May 18, 2017
Author Contributor

Taken from the original help output.

This comment has been minimized.

@Radiergummi

Radiergummi May 18, 2017
Author Contributor

Fixed.

#
# admin:user:create
#
__fish_magento_register_command_option admin:user:create -f -r -l admin-user -d "(Required) Admin user";

This comment has been minimized.

@faho

faho May 18, 2017
Member

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'

This comment has been minimized.

@faho

faho May 18, 2017
Member

(Note: Ideally you'd suggest only the ones that haven't been given yet. See __fish_contains_opt)

This comment has been minimized.

@Radiergummi

Radiergummi May 18, 2017
Author Contributor

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";

This comment has been minimized.

@faho

faho May 18, 2017
Member

"Output as XML".

This comment has been minimized.

@Radiergummi

Radiergummi May 18, 2017
Author Contributor

Taken from the original help output.

This comment has been minimized.

@Radiergummi

Radiergummi May 18, 2017
Author Contributor

Fixed.

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";

This comment has been minimized.

@faho

faho May 18, 2017
Member

I'm assuming the "ANSI" here refers to ANSI color codes? Then it should be "Force colored output".

This comment has been minimized.

@Radiergummi

Radiergummi May 18, 2017
Author Contributor

Same as above, taken from Magento help output

This comment has been minimized.

@Radiergummi

Radiergummi May 18, 2017
Author Contributor

Fixed.

#
# 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.';

This comment has been minimized.

@faho

faho May 18, 2017
Member

You probably still want to complete these commands, even if you can't complete the arguments.

This comment has been minimized.

@Radiergummi

Radiergummi May 18, 2017
Author Contributor

Well they don't have any parameters, and I've registered the subcommand itself already, so that should be fine, shouldn't it?

This comment has been minimized.

@faho

faho May 18, 2017
Member

You have? Sorry, I must have missed that!

Radiergummi added 2 commits May 18, 2017
Tried to shorten the text as much as possible and removed unnecessary characters
@faho
faho approved these changes May 18, 2017
@faho faho added this to the 2.6.0 milestone May 18, 2017
@faho faho merged commit 71f5fe1 into fish-shell:master May 18, 2017
1 check failed
1 check failed
continuous-integration/travis-ci/pr The Travis CI build failed
Details
@faho
Copy link
Member

@faho faho commented May 18, 2017

Merged, thanks!

@zanchey: This is good for 2.6.0.

zanchey added a commit that referenced this pull request May 19, 2017
* 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)
@zanchey
Copy link
Member

@zanchey zanchey commented May 19, 2017

Thanks, taken for 2.6.0 as 291d88a.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.