From 3db247fc49d6805110e9bc53d5420ace6927a3ab Mon Sep 17 00:00:00 2001 From: Doug Cone Date: Mon, 30 Sep 2019 08:52:00 -0400 Subject: [PATCH 1/3] add autocomplete command and script --- .circleci/config.yml | 1 + composer.json | 39 ++++++++++---------- composer.lock | 52 ++++++++++++++++++++++++++- scripts/build-autocomplete.php | 14 ++++++++ src/Commands/AutocompleteCommand.php | 54 ++++++++++++++++++++++++++++ src/Terminus.php | 1 + 6 files changed, 142 insertions(+), 19 deletions(-) create mode 100644 scripts/build-autocomplete.php create mode 100644 src/Commands/AutocompleteCommand.php diff --git a/.circleci/config.yml b/.circleci/config.yml index d47122e6a..8a25570cd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -16,6 +16,7 @@ jobs: # Install without dev components to build a smaller phar - run: composer install --no-dev --no-interaction --prefer-dist - run: composer phar:install-tools + - run: composer global require bamarni/symfony-console-autocomplete - run: composer phar:build # Re-install with dev components so that we can run phpunit - run: composer install --no-interaction --prefer-dist diff --git a/composer.json b/composer.json index cb31e18de..06fb94cd8 100644 --- a/composer.json +++ b/composer.json @@ -36,26 +36,29 @@ "bin/terminus" ], "scripts": { - "phar:install-tools": [ - "gem install mime-types -v 2.6.2", - "curl -LSs https://box-project.github.io/box2/installer.php | php", - "mkdir -p tools", - "mv -f box.phar tools/box" - ], - "phar:build": "env PATH=tools:$PATH box build", - "update-class-lists": ["\\Terminus\\UpdateClassLists::update"], - "behat": "SHELL_INTERACTIVE=true behat --colors --config tests/config/behat.yml --suite=default", - "cbf": "phpcbf --standard=PSR2 -n tests/unit_tests/* bin/terminus src/*", - "clover": "phpunit -c tests/config/phpunit.xml.dist --coverage-clover tests/logs/clover.xml", - "coveralls": "php vendor/bin/php-coveralls -v -c tests/config/coveralls.yml", - "cs": "phpcs --standard=PSR2 --severity=1 -n tests/unit_tests bin/terminus src", - "docs": "php scripts/make-docs.php", - "lint": "@cs", - "phpunit": "SHELL_INTERACTIVE=true phpunit --colors=always -c tests/config/phpunit.xml.dist --debug", - "functional": "phpunit --colors=always -c tests/config/functional.phpunit.xml.dist --debug", - "test": "set -ex ; composer cs ; composer phpunit ; composer behat ; composer functional" + "phar:install-tools": [ + "gem install mime-types -v 2.6.2", + "curl -LSs https://box-project.github.io/box2/installer.php | php", + "mkdir -p tools", + "mv -f box.phar tools/box" + ], + "autocomplete:build": "php scripts/build-autocomplete.php", + "phar:build": "env PATH=tools:$PATH box build", + "update-class-lists": ["\\Terminus\\UpdateClassLists::update"], + "behat": "SHELL_INTERACTIVE=true behat --colors --config tests/config/behat.yml --suite=default", + "cbf": "phpcbf --standard=PSR2 -n tests/unit_tests/* bin/terminus src/*", + "clover": "phpunit -c tests/config/phpunit.xml.dist --coverage-clover tests/logs/clover.xml", + "coveralls": "php vendor/bin/php-coveralls -v -c tests/config/coveralls.yml", + "cs": "phpcs --standard=PSR2 --severity=1 -n tests/unit_tests bin/terminus src", + "docs": "php scripts/make-docs.php", + "lint": "@cs", + "phpunit": "SHELL_INTERACTIVE=true phpunit --colors=always -c tests/config/phpunit.xml.dist --debug", + "functional": "phpunit --colors=always -c tests/config/functional.phpunit.xml.dist --debug", + "test": "set -ex ; composer cs ; composer phpunit ; composer behat ; composer functional", + "post-install-cmd": "php scripts/build-autocomplete.php" }, "require-dev": { + "bamarni/symfony-console-autocomplete": "^1.3", "behat/behat": "^3.2.2", "php-vcr/php-vcr": "^1.4", "phpunit/phpunit": "^4.8.36", diff --git a/composer.lock b/composer.lock index 4a611a222..89616abae 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "73159373e760344d19f0d07481f66f2e", + "content-hash": "f5dbc7680a88c2bddb6083b814de70f4", "packages": [ { "name": "composer/semver", @@ -2160,6 +2160,56 @@ } ], "packages-dev": [ + { + "name": "bamarni/symfony-console-autocomplete", + "version": "v1.3.5", + "source": { + "type": "git", + "url": "https://github.com/bamarni/symfony-console-autocomplete.git", + "reference": "0fb747e5fdad1f4a028ef42a02bc4a3c4ef8fc12" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/bamarni/symfony-console-autocomplete/zipball/0fb747e5fdad1f4a028ef42a02bc4a3c4ef8fc12", + "reference": "0fb747e5fdad1f4a028ef42a02bc4a3c4ef8fc12", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "symfony/console": "^2.5|^3|^4", + "symfony/process": "^2.5|^3|^4" + }, + "require-dev": { + "symfony/console": "2.8.*" + }, + "bin": [ + "bin/symfony-autocomplete" + ], + "type": "library", + "autoload": { + "psr-4": { + "Bamarni\\Symfony\\Console\\Autocomplete\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bilal Amarni", + "email": "bilal.amarni@gmail.com", + "role": "Lead developer" + }, + { + "name": "Richard Quadling", + "email": "RQuadling@gmail.com", + "role": "Contributing developer" + } + ], + "description": "Shell completion for Symfony Console based scripts", + "time": "2019-08-02T15:22:55+00:00" + }, { "name": "beberlei/assert", "version": "v2.9.9", diff --git a/scripts/build-autocomplete.php b/scripts/build-autocomplete.php new file mode 100644 index 000000000..97ad0f3db --- /dev/null +++ b/scripts/build-autocomplete.php @@ -0,0 +1,14 @@ + 0 ) { + // global install? + $autocomplete = shell_exec('symfony-autocomplete bin/terminus'); + file_put_contents('assets/autocomplete.txt', $autocomplete); +} else { + echo "Please install dev dependencies, or run composer global require bamarni/symfony-console-autocomplete"; + exit(1); +} diff --git a/src/Commands/AutocompleteCommand.php b/src/Commands/AutocompleteCommand.php new file mode 100644 index 000000000..1b49edef1 --- /dev/null +++ b/src/Commands/AutocompleteCommand.php @@ -0,0 +1,54 @@ +retrieveList(); + } + + /** + * Return the filename. + * + * @return string + */ + protected function getFilename() + { + return $this->config->get('assets_dir') . "/autocomplete.txt"; + } + + /** + * Retrieve the contents of the autocomplete file. + * + * @return string + * @throws TerminusNotFoundException + */ + protected function retrieveList() + { + $filename = $this->getFilename(); + $local_machine_helper = $this->getContainer()->get(LocalMachineHelper::class); + if (!$local_machine_helper->getFilesystem()->exists($filename)) { + throw new TerminusNotFoundException( + 'Please generate the autocomplete script using the `composer autocomplete:build` command.' + ); + } + return $local_machine_helper->readFile($filename); + } +} diff --git a/src/Terminus.php b/src/Terminus.php index 555af9134..914cdde7e 100644 --- a/src/Terminus.php +++ b/src/Terminus.php @@ -125,6 +125,7 @@ private function addBuiltInCommandsAndHooks() 'Pantheon\\Terminus\\Hooks\\Authorizer', 'Pantheon\\Terminus\\Hooks\\SiteEnvLookup', 'Pantheon\\Terminus\\Commands\\AliasesCommand', + 'Pantheon\\Terminus\\Commands\\AutocompleteCommand', 'Pantheon\\Terminus\\Commands\\ArtCommand', 'Pantheon\\Terminus\\Commands\\Auth\\LoginCommand', 'Pantheon\\Terminus\\Commands\\Auth\\LogoutCommand', From c7ba99114f6ae9bca58324dfc6882a5f4ee31eb3 Mon Sep 17 00:00:00 2001 From: Doug Cone Date: Mon, 30 Sep 2019 08:52:00 -0400 Subject: [PATCH 2/3] add autocomplete command and script --- .circleci/config.yml | 1 + composer.json | 39 ++++++++++---------- composer.lock | 52 ++++++++++++++++++++++++++- scripts/build-autocomplete.php | 14 ++++++++ src/Commands/AutocompleteCommand.php | 54 ++++++++++++++++++++++++++++ src/Terminus.php | 1 + 6 files changed, 142 insertions(+), 19 deletions(-) create mode 100644 scripts/build-autocomplete.php create mode 100644 src/Commands/AutocompleteCommand.php diff --git a/.circleci/config.yml b/.circleci/config.yml index d47122e6a..8a25570cd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -16,6 +16,7 @@ jobs: # Install without dev components to build a smaller phar - run: composer install --no-dev --no-interaction --prefer-dist - run: composer phar:install-tools + - run: composer global require bamarni/symfony-console-autocomplete - run: composer phar:build # Re-install with dev components so that we can run phpunit - run: composer install --no-interaction --prefer-dist diff --git a/composer.json b/composer.json index cb31e18de..06fb94cd8 100644 --- a/composer.json +++ b/composer.json @@ -36,26 +36,29 @@ "bin/terminus" ], "scripts": { - "phar:install-tools": [ - "gem install mime-types -v 2.6.2", - "curl -LSs https://box-project.github.io/box2/installer.php | php", - "mkdir -p tools", - "mv -f box.phar tools/box" - ], - "phar:build": "env PATH=tools:$PATH box build", - "update-class-lists": ["\\Terminus\\UpdateClassLists::update"], - "behat": "SHELL_INTERACTIVE=true behat --colors --config tests/config/behat.yml --suite=default", - "cbf": "phpcbf --standard=PSR2 -n tests/unit_tests/* bin/terminus src/*", - "clover": "phpunit -c tests/config/phpunit.xml.dist --coverage-clover tests/logs/clover.xml", - "coveralls": "php vendor/bin/php-coveralls -v -c tests/config/coveralls.yml", - "cs": "phpcs --standard=PSR2 --severity=1 -n tests/unit_tests bin/terminus src", - "docs": "php scripts/make-docs.php", - "lint": "@cs", - "phpunit": "SHELL_INTERACTIVE=true phpunit --colors=always -c tests/config/phpunit.xml.dist --debug", - "functional": "phpunit --colors=always -c tests/config/functional.phpunit.xml.dist --debug", - "test": "set -ex ; composer cs ; composer phpunit ; composer behat ; composer functional" + "phar:install-tools": [ + "gem install mime-types -v 2.6.2", + "curl -LSs https://box-project.github.io/box2/installer.php | php", + "mkdir -p tools", + "mv -f box.phar tools/box" + ], + "autocomplete:build": "php scripts/build-autocomplete.php", + "phar:build": "env PATH=tools:$PATH box build", + "update-class-lists": ["\\Terminus\\UpdateClassLists::update"], + "behat": "SHELL_INTERACTIVE=true behat --colors --config tests/config/behat.yml --suite=default", + "cbf": "phpcbf --standard=PSR2 -n tests/unit_tests/* bin/terminus src/*", + "clover": "phpunit -c tests/config/phpunit.xml.dist --coverage-clover tests/logs/clover.xml", + "coveralls": "php vendor/bin/php-coveralls -v -c tests/config/coveralls.yml", + "cs": "phpcs --standard=PSR2 --severity=1 -n tests/unit_tests bin/terminus src", + "docs": "php scripts/make-docs.php", + "lint": "@cs", + "phpunit": "SHELL_INTERACTIVE=true phpunit --colors=always -c tests/config/phpunit.xml.dist --debug", + "functional": "phpunit --colors=always -c tests/config/functional.phpunit.xml.dist --debug", + "test": "set -ex ; composer cs ; composer phpunit ; composer behat ; composer functional", + "post-install-cmd": "php scripts/build-autocomplete.php" }, "require-dev": { + "bamarni/symfony-console-autocomplete": "^1.3", "behat/behat": "^3.2.2", "php-vcr/php-vcr": "^1.4", "phpunit/phpunit": "^4.8.36", diff --git a/composer.lock b/composer.lock index 4a611a222..89616abae 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "73159373e760344d19f0d07481f66f2e", + "content-hash": "f5dbc7680a88c2bddb6083b814de70f4", "packages": [ { "name": "composer/semver", @@ -2160,6 +2160,56 @@ } ], "packages-dev": [ + { + "name": "bamarni/symfony-console-autocomplete", + "version": "v1.3.5", + "source": { + "type": "git", + "url": "https://github.com/bamarni/symfony-console-autocomplete.git", + "reference": "0fb747e5fdad1f4a028ef42a02bc4a3c4ef8fc12" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/bamarni/symfony-console-autocomplete/zipball/0fb747e5fdad1f4a028ef42a02bc4a3c4ef8fc12", + "reference": "0fb747e5fdad1f4a028ef42a02bc4a3c4ef8fc12", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "symfony/console": "^2.5|^3|^4", + "symfony/process": "^2.5|^3|^4" + }, + "require-dev": { + "symfony/console": "2.8.*" + }, + "bin": [ + "bin/symfony-autocomplete" + ], + "type": "library", + "autoload": { + "psr-4": { + "Bamarni\\Symfony\\Console\\Autocomplete\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bilal Amarni", + "email": "bilal.amarni@gmail.com", + "role": "Lead developer" + }, + { + "name": "Richard Quadling", + "email": "RQuadling@gmail.com", + "role": "Contributing developer" + } + ], + "description": "Shell completion for Symfony Console based scripts", + "time": "2019-08-02T15:22:55+00:00" + }, { "name": "beberlei/assert", "version": "v2.9.9", diff --git a/scripts/build-autocomplete.php b/scripts/build-autocomplete.php new file mode 100644 index 000000000..97ad0f3db --- /dev/null +++ b/scripts/build-autocomplete.php @@ -0,0 +1,14 @@ + 0 ) { + // global install? + $autocomplete = shell_exec('symfony-autocomplete bin/terminus'); + file_put_contents('assets/autocomplete.txt', $autocomplete); +} else { + echo "Please install dev dependencies, or run composer global require bamarni/symfony-console-autocomplete"; + exit(1); +} diff --git a/src/Commands/AutocompleteCommand.php b/src/Commands/AutocompleteCommand.php new file mode 100644 index 000000000..1b49edef1 --- /dev/null +++ b/src/Commands/AutocompleteCommand.php @@ -0,0 +1,54 @@ +retrieveList(); + } + + /** + * Return the filename. + * + * @return string + */ + protected function getFilename() + { + return $this->config->get('assets_dir') . "/autocomplete.txt"; + } + + /** + * Retrieve the contents of the autocomplete file. + * + * @return string + * @throws TerminusNotFoundException + */ + protected function retrieveList() + { + $filename = $this->getFilename(); + $local_machine_helper = $this->getContainer()->get(LocalMachineHelper::class); + if (!$local_machine_helper->getFilesystem()->exists($filename)) { + throw new TerminusNotFoundException( + 'Please generate the autocomplete script using the `composer autocomplete:build` command.' + ); + } + return $local_machine_helper->readFile($filename); + } +} diff --git a/src/Terminus.php b/src/Terminus.php index 555af9134..914cdde7e 100644 --- a/src/Terminus.php +++ b/src/Terminus.php @@ -125,6 +125,7 @@ private function addBuiltInCommandsAndHooks() 'Pantheon\\Terminus\\Hooks\\Authorizer', 'Pantheon\\Terminus\\Hooks\\SiteEnvLookup', 'Pantheon\\Terminus\\Commands\\AliasesCommand', + 'Pantheon\\Terminus\\Commands\\AutocompleteCommand', 'Pantheon\\Terminus\\Commands\\ArtCommand', 'Pantheon\\Terminus\\Commands\\Auth\\LoginCommand', 'Pantheon\\Terminus\\Commands\\Auth\\LogoutCommand', From 71822e7cf10b3f925b95e089ef5eac1668efecb1 Mon Sep 17 00:00:00 2001 From: Doug Cone Date: Fri, 11 Oct 2019 08:00:48 -0400 Subject: [PATCH 3/3] fix phpcs spacing issue --- src/Commands/AutocompleteCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/AutocompleteCommand.php b/src/Commands/AutocompleteCommand.php index 1b49edef1..86abb6c07 100644 --- a/src/Commands/AutocompleteCommand.php +++ b/src/Commands/AutocompleteCommand.php @@ -19,7 +19,7 @@ class AutocompleteCommand extends TerminusCommand * * @usage Returns the shell autocomplete config. */ - public function autocomplete() + public function autocomplete() { return $this->retrieveList(); }