diff --git a/.travis.yml b/.travis.yml index c4b868432..c5efe4579 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,6 +26,7 @@ env: matrix: - SCRIPT_JOB="PHP-CS-FIXER" - SCRIPT_JOB="BUILDSH" + - SCRIPT_JOB="BASH-AUTOCOMPLETION" - MAGENTO_VERSION="magento-ce-2.1.4" INSTALL_SAMPLE_DATA=0 - MAGENTO_VERSION="magento-ce-2.1.3" INSTALL_SAMPLE_DATA=0 - MAGENTO_VERSION="magento-ce-2.1.2" INSTALL_SAMPLE_DATA=0 @@ -58,6 +59,8 @@ matrix: env: SCRIPT_JOB="PHP-CS-FIXER" - php: 7.1 env: SCRIPT_JOB="BUILDSH" + - php: 7.1 + env: SCRIPT_JOB="BASH-AUTOCOMPLETION" before_install: - phpenv config-rm xdebug.ini diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d3684d74..0290c953d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ RECENT CHANGES * Imp: Support NULL values in config:set and config:get (by Tom Klingenberg, #208) * Imp: Better handle incomplete Magento 2 installments (by Tom Klingenberg) * Imp: Dispatch adminhtml_cache_flush_all with cache:flush (report by Viktor Steinwand, #263) +* New: Compilation of the bash autocomplete-file (by Tom Klingenberg) * New: Add current Magento2 versions (thanks Pieter Hoste, #270) * New: Add current Magento2 versions (by Tom Klingenberg) * New: Add sys:cron:schedule command (by Pieter Hoste, #257) diff --git a/bin/compile-bash-autocompletion b/bin/compile-bash-autocompletion new file mode 120000 index 000000000..9b9e416d7 --- /dev/null +++ b/bin/compile-bash-autocompletion @@ -0,0 +1 @@ +../build/bin/compile-bash-autocompletion.sh \ No newline at end of file diff --git a/build/bin/compile-bash-autocompletion.sh b/build/bin/compile-bash-autocompletion.sh new file mode 100755 index 000000000..9576724aa --- /dev/null +++ b/build/bin/compile-bash-autocompletion.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# +# compile-bash-autocompletion +# +# generate bash autocompletion file for magerun +# +set -euo pipefail +IFS=$'\n\t' + +header() +{ + cat <&2 echo "error: could not find 'bin/${name}' script" + exit 1 +fi + +echo "creating bash autocomplete file (this takes a little moment).." + +header > "${outfile}" +vendor/bin/symfony-autocomplete -- "bin/${name}" \ + | sed '1d ; $ s/$/.phar '"${name} ${base}"'/' \ + >> "${outfile}" +# sed: remove first line and expand last line to more command names (aliases) + +echo "updated \"${outfile}\"." diff --git a/build/travis/script.sh b/build/travis/script.sh index 50ba7ccf1..8e897279b 100755 --- a/build/travis/script.sh +++ b/build/travis/script.sh @@ -51,4 +51,8 @@ case "${SCRIPT_JOB}" in build/travis/build.sh ;; + "BASH-AUTOCOMPLETION" ) + bin/compile-bash-autocompletion + ;; + esac diff --git a/composer.json b/composer.json index a424c53d5..fc5b20c0e 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "twig/twig": "~1.0" }, "require-dev": { + "bamarni/symfony-console-autocomplete": "^1.2.0", "friendsofphp/php-cs-fixer": "~1.12.0", "mikey179/vfsStream": "~1.4", "phing/phing": "~2.10.0", diff --git a/composer.lock b/composer.lock index 1420f82fd..86c07e03d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "1ea5d5671139b6721656f997c10c03b0", + "content-hash": "198640dc475a3d96f727ef5c992a0d5f", "packages": [ { "name": "composer/ca-bundle", @@ -1539,6 +1539,44 @@ } ], "packages-dev": [ + { + "name": "bamarni/symfony-console-autocomplete", + "version": "v1.2.0", + "source": { + "type": "git", + "url": "https://github.com/bamarni/symfony-console-autocomplete.git", + "reference": "0f224ae25d13b79aef353767af43d420d1f96b13" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/bamarni/symfony-console-autocomplete/zipball/0f224ae25d13b79aef353767af43d420d1f96b13", + "reference": "0f224ae25d13b79aef353767af43d420d1f96b13", + "shasum": "" + }, + "require": { + "symfony/console": "^2.5|3.*", + "symfony/process": "^2.3|3.*" + }, + "require-dev": { + "symfony/console": "2.8.*" + }, + "bin": [ + "symfony-autocomplete" + ], + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bilal Amarni", + "email": "bilal.amarni@gmail.com" + } + ], + "description": "Shell completion for Symfony Console based scripts", + "time": "2016-02-14T10:55:22+00:00" + }, { "name": "doctrine/instantiator", "version": "1.0.5", diff --git a/readme.rst b/readme.rst index 8924f7985..152fb2465 100644 --- a/readme.rst +++ b/readme.rst @@ -86,6 +86,37 @@ You can now use the tools: $ n98-magerun2 {command} +Autocompletion +-------------- + +Files for autocompletion with Magerun can be found inside the folder `res/autocompletion`, In +the following some more information about a specific one (Bash), there are +more (e.g. Fish, Zsh). + +Bash +"""" + +Bash completion is available pre-generated, all commands and their respective +options are availble on tab. To get completion for an otion type two dashes +("--") and then tab. + +To install the completion files, copy **n98-magerun.phar.bash** to your bash +compatdir folder for autocompletion. + +On my Ubuntu system this can be done with the following command: + +.. code-block:: sh + + # cp res/autocompletion/bash/n98-magerun.phar.bash /etc/bash_completion.d + +The concrete folder can be obtained via pkg-config:: + +.. code-block:: sh + +# pkg-config --variable=compatdir bash-completion + +Detailed information is available in the bash-completions FAQ: https://github.com/scop/bash-completion#faq + Usage / Commands ---------------- @@ -298,7 +329,7 @@ If no code is specified, all cache types will be enabled. Run `cache:list` command to see all codes. EAV Attributes -""""""""""""""""" +"""""""""""""" View the data for a particular attribute: @@ -307,7 +338,7 @@ View the data for a particular attribute: $ n98-magerun2.phar eav:attribute:view [--format[="..."]] entityType attributeCode Generate Gift Card Pool -""""""""""""""""" +""""""""""""""""""""""" Generates a new gift card pool. @@ -316,7 +347,7 @@ Generates a new gift card pool. $ n98-magerun2.phar giftcard:pool:generate Create a Gift Card -""""""""""""""""" +"""""""""""""""""" .. code-block:: sh @@ -326,14 +357,14 @@ You may specify a website ID or use the default. You may also optionally add an using the `--expires` option. Dates should be in `YYYY-MM-DD` format. View Gift Card Information -""""""""""""""""" +"""""""""""""""""""""""""" .. code-block:: sh $ n98-magerun2.phar giftcard:info [--format[="..."]] [code] Remove a Gift Card -""""""""""""""""" +"""""""""""""""""" .. code-block:: sh @@ -354,7 +385,7 @@ Compares module version with saved setup version in `setup_module` table and dis Change Setup Version """""""""""""""""""" -Changes the version of a module. This command is useful if you want to re-run an upgrade script again possibly for +Changes the version of a module. This command is useful if you want to re-run an upgrade script again possibly for debugging. Alternatively you would have to alter the row in the database manually. .. code-block:: sh diff --git a/res/autocompletion/bash/n98-magerun2.phar.bash b/res/autocompletion/bash/n98-magerun2.phar.bash new file mode 100644 index 000000000..9543cbdae --- /dev/null +++ b/res/autocompletion/bash/n98-magerun2.phar.bash @@ -0,0 +1,403 @@ +#!/bin/bash +# Installation: +# Copy to /etc/bash_completion.d/n98-magerun.phar +# or +# Append to ~/.bash_completion +# open new or restart existing shell session + + +_n98-magerun2() +{ + local cur script coms opts com + COMPREPLY=() + _get_comp_words_by_ref -n : cur words + + # for an alias, get the real script behind it + if [[ $(type -t ${words[0]}) == "alias" ]]; then + script=$(alias ${words[0]} | sed -E "s/alias ${words[0]}='(.*)'/\1/") + else + script=${words[0]} + fi + + # lookup for command + for word in ${words[@]:1}; do + if [[ $word != -* ]]; then + com=$word + break + fi + done + + # completing for an option + if [[ ${cur} == --* ]] ; then + opts="--help --quiet --verbose --version --ansi --no-ansi --no-interaction --root-dir --skip-config --skip-root-check --skip-core-commands" + + case "$com" in + help) + opts="${opts} --xml --format --raw" + ;; + install) + opts="${opts} --magentoVersion --magentoVersionByName --installationFolder --dbHost --dbUser --dbPass --dbName --dbPort --installSampleData --useDefaultConfigParams --baseUrl --replaceHtaccessFile --noDownload --only-download --forceUseDb" + ;; + list) + opts="${opts} --xml --raw --format" + ;; + open-browser) + opts="${opts} " + ;; + script) + opts="${opts} --define --stop-on-error" + ;; + shell) + opts="${opts} " + ;; + admin:notifications) + opts="${opts} --on --off" + ;; + admin:user:change-password) + opts="${opts} " + ;; + admin:user:create) + opts="${opts} --admin-user --admin-password --admin-email --admin-firstname --admin-lastname --magento-init-params" + ;; + admin:user:delete) + opts="${opts} --force" + ;; + admin:user:list) + opts="${opts} --format" + ;; + admin:user:unlock) + opts="${opts} " + ;; + cache:clean) + opts="${opts} " + ;; + cache:disable) + opts="${opts} --format" + ;; + cache:enable) + opts="${opts} --format" + ;; + cache:flush) + opts="${opts} " + ;; + cache:list) + opts="${opts} --enabled --format" + ;; + cache:status) + opts="${opts} --bootstrap" + ;; + catalog:images:resize) + opts="${opts} " + ;; + catalog:product:attributes:cleanup) + opts="${opts} " + ;; + config:delete) + opts="${opts} --scope --scope-id --all" + ;; + config:get) + opts="${opts} --scope --scope-id --decrypt --update-script --magerun-script --format" + ;; + config:set) + opts="${opts} --scope --scope-id --encrypt --no-null" + ;; + cron:run) + opts="${opts} --group --bootstrap" + ;; + customer:create) + opts="${opts} --format" + ;; + customer:hash:upgrade) + opts="${opts} " + ;; + customer:info) + opts="${opts} " + ;; + customer:list) + opts="${opts} --format" + ;; + db:console) + opts="${opts} --connection" + ;; + db:create) + opts="${opts} --connection" + ;; + db:drop) + opts="${opts} --connection --tables --force" + ;; + db:dump) + opts="${opts} --connection --add-time --compression --only-command --print-only-filename --dry-run --no-single-transaction --human-readable --add-routines --stdout --strip --force" + ;; + db:import) + opts="${opts} --connection --compression --only-command --only-if-empty --optimize --drop --drop-tables" + ;; + db:info) + opts="${opts} --connection --format" + ;; + db:maintain:check-tables) + opts="${opts} --type --repair --table --format" + ;; + db:query) + opts="${opts} --connection --only-command" + ;; + db:status) + opts="${opts} --connection --format --rounding --no-description" + ;; + db:variables) + opts="${opts} --connection --format --rounding --no-description" + ;; + deploy:mode:set) + opts="${opts} --skip-compilation" + ;; + deploy:mode:show) + opts="${opts} " + ;; + design:demo-notice) + opts="${opts} --on --off --global" + ;; + dev:console) + opts="${opts} " + ;; + dev:module:create) + opts="${opts} --minimal --add-blocks --add-helpers --add-models --add-setup --add-all --enable --modman --add-readme --add-composer --author-name --author-email --description" + ;; + dev:module:list) + opts="${opts} --vendor --format" + ;; + dev:module:observer:list) + opts="${opts} --format --sort" + ;; + dev:report:count) + opts="${opts} " + ;; + dev:source-theme:deploy) + opts="${opts} --type --locale --area --theme" + ;; + dev:symlinks) + opts="${opts} --on --off --global" + ;; + dev:template-hints) + opts="${opts} --on --off" + ;; + dev:template-hints-blocks) + opts="${opts} --on --off" + ;; + dev:tests:run) + opts="${opts} " + ;; + dev:theme:list) + opts="${opts} --format" + ;; + dev:urn-catalog:generate) + opts="${opts} --ide" + ;; + dev:xml:convert) + opts="${opts} --overwrite" + ;; + eav:attribute:view) + opts="${opts} --format" + ;; + generation:flush) + opts="${opts} " + ;; + i18n:collect-phrases) + opts="${opts} --output --magento" + ;; + i18n:pack) + opts="${opts} --mode --allow-duplicates" + ;; + i18n:uninstall) + opts="${opts} --backup-code" + ;; + index:list) + opts="${opts} --format" + ;; + indexer:info) + opts="${opts} " + ;; + indexer:reindex) + opts="${opts} " + ;; + indexer:reset) + opts="${opts} " + ;; + indexer:set-mode) + opts="${opts} " + ;; + indexer:show-mode) + opts="${opts} " + ;; + indexer:status) + opts="${opts} " + ;; + info:adminuri) + opts="${opts} " + ;; + info:backups:list) + opts="${opts} " + ;; + info:currency:list) + opts="${opts} " + ;; + info:dependencies:show-framework) + opts="${opts} --output" + ;; + info:dependencies:show-modules) + opts="${opts} --output" + ;; + info:dependencies:show-modules-circular) + opts="${opts} --output" + ;; + info:language:list) + opts="${opts} " + ;; + info:timezone:list) + opts="${opts} " + ;; + maintenance:allow-ips) + opts="${opts} --none --magento-init-params" + ;; + maintenance:disable) + opts="${opts} --ip --magento-init-params" + ;; + maintenance:enable) + opts="${opts} --ip --magento-init-params" + ;; + maintenance:status) + opts="${opts} --magento-init-params" + ;; + module:disable) + opts="${opts} --force --all --clear-static-content --magento-init-params" + ;; + module:enable) + opts="${opts} --force --all --clear-static-content --magento-init-params" + ;; + module:status) + opts="${opts} --magento-init-params" + ;; + module:uninstall) + opts="${opts} --remove-data --backup-code --backup-media --backup-db --clear-static-content --magento-init-params" + ;; + sampledata:deploy) + opts="${opts} " + ;; + sampledata:remove) + opts="${opts} " + ;; + sampledata:reset) + opts="${opts} " + ;; + script:repo:list) + opts="${opts} --format" + ;; + script:repo:run) + opts="${opts} --define --stop-on-error" + ;; + setup:backup) + opts="${opts} --code --media --db --magento-init-params" + ;; + setup:config:set) + opts="${opts} --backend-frontname --key --session-save --definition-format --db-host --db-name --db-user --db-engine --db-password --db-prefix --db-model --db-init-statements --skip-db-validation --http-cache-hosts --magento-init-params" + ;; + setup:cron:run) + opts="${opts} --magento-init-params" + ;; + setup:db-data:upgrade) + opts="${opts} --magento-init-params" + ;; + setup:db-schema:upgrade) + opts="${opts} --magento-init-params" + ;; + setup:db:status) + opts="${opts} --magento-init-params" + ;; + setup:di:compile) + opts="${opts} " + ;; + setup:install) + opts="${opts} --backend-frontname --key --session-save --definition-format --db-host --db-name --db-user --db-engine --db-password --db-prefix --db-model --db-init-statements --skip-db-validation --http-cache-hosts --base-url --language --timezone --currency --use-rewrites --use-secure --base-url-secure --use-secure-admin --admin-use-security-key --admin-user --admin-password --admin-email --admin-firstname --admin-lastname --cleanup-database --sales-order-increment-prefix --use-sample-data --magento-init-params" + ;; + setup:performance:generate-fixtures) + opts="${opts} --skip-reindex" + ;; + setup:rollback) + opts="${opts} --code-file --media-file --db-file --magento-init-params" + ;; + setup:static-content:deploy) + opts="${opts} --dry-run --no-javascript --no-css --no-less --no-images --no-fonts --no-html --no-misc --no-html-minify --theme --exclude-theme --language --exclude-language --area --exclude-area --jobs" + ;; + setup:store-config:set) + opts="${opts} --base-url --language --timezone --currency --use-rewrites --use-secure --base-url-secure --use-secure-admin --admin-use-security-key --magento-init-params" + ;; + setup:uninstall) + opts="${opts} --magento-init-params" + ;; + setup:upgrade) + opts="${opts} --keep-generated --magento-init-params" + ;; + sys:check) + opts="${opts} --format" + ;; + sys:cron:history) + opts="${opts} --timezone --format" + ;; + sys:cron:list) + opts="${opts} --format" + ;; + sys:cron:run) + opts="${opts} " + ;; + sys:cron:schedule) + opts="${opts} " + ;; + sys:info) + opts="${opts} --format" + ;; + sys:maintenance) + opts="${opts} --on --off" + ;; + sys:setup:change-version) + opts="${opts} " + ;; + sys:setup:compare-versions) + opts="${opts} --ignore-data --log-junit --format" + ;; + sys:setup:downgrade-versions) + opts="${opts} --dry-run" + ;; + sys:store:config:base-url:list) + opts="${opts} --format" + ;; + sys:store:list) + opts="${opts} --format" + ;; + sys:url:list) + opts="${opts} --add-categories --add-products --add-cmspages --add-all" + ;; + sys:website:list) + opts="${opts} --format" + ;; + theme:uninstall) + opts="${opts} --backup-code --clear-static-content" + ;; + + esac + + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + __ltrim_colon_completions "$cur" + + return 0; + fi + + # completing for a command + if [[ $cur == $com ]]; then + coms="help install list open-browser script shell admin:notifications admin:user:change-password admin:user:create admin:user:delete admin:user:list admin:user:unlock cache:clean cache:disable cache:enable cache:flush cache:list cache:status catalog:images:resize catalog:product:attributes:cleanup config:delete config:get config:set cron:run customer:create customer:hash:upgrade customer:info customer:list db:console db:create db:drop db:dump db:import db:info db:maintain:check-tables db:query db:status db:variables deploy:mode:set deploy:mode:show design:demo-notice dev:console dev:module:create dev:module:list dev:module:observer:list dev:report:count dev:source-theme:deploy dev:symlinks dev:template-hints dev:template-hints-blocks dev:tests:run dev:theme:list dev:urn-catalog:generate dev:xml:convert eav:attribute:view generation:flush i18n:collect-phrases i18n:pack i18n:uninstall index:list indexer:info indexer:reindex indexer:reset indexer:set-mode indexer:show-mode indexer:status info:adminuri info:backups:list info:currency:list info:dependencies:show-framework info:dependencies:show-modules info:dependencies:show-modules-circular info:language:list info:timezone:list maintenance:allow-ips maintenance:disable maintenance:enable maintenance:status module:disable module:enable module:status module:uninstall sampledata:deploy sampledata:remove sampledata:reset script:repo:list script:repo:run setup:backup setup:config:set setup:cron:run setup:db-data:upgrade setup:db-schema:upgrade setup:db:status setup:di:compile setup:install setup:performance:generate-fixtures setup:rollback setup:static-content:deploy setup:store-config:set setup:uninstall setup:upgrade sys:check sys:cron:history sys:cron:list sys:cron:run sys:cron:schedule sys:info sys:maintenance sys:setup:change-version sys:setup:compare-versions sys:setup:downgrade-versions sys:store:config:base-url:list sys:store:list sys:url:list sys:website:list theme:uninstall" + + COMPREPLY=($(compgen -W "${coms}" -- ${cur})) + __ltrim_colon_completions "$cur" + + return 0 + fi +} + +complete -o default -F _n98-magerun2 n98-magerun2.phar n98-magerun2 magerun2 diff --git a/autocompletion/fish/n98-magerun2.phar.fish b/res/autocompletion/fish/n98-magerun2.phar.fish similarity index 100% rename from autocompletion/fish/n98-magerun2.phar.fish rename to res/autocompletion/fish/n98-magerun2.phar.fish diff --git a/autocompletion/zsh/n98-magerun2.plugin.zsh b/res/autocompletion/zsh/n98-magerun2.plugin.zsh similarity index 100% rename from autocompletion/zsh/n98-magerun2.plugin.zsh rename to res/autocompletion/zsh/n98-magerun2.plugin.zsh