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

Autocomplete #2023

Open
wants to merge 4 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 21 additions & 18 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
52 changes: 51 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions scripts/build-autocomplete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
// are dev requirements installed?
if ( file_exists('vendor/bin/symfony-autocomplete') ) {
$autocomplete = shell_exec('vendor/bin/symfony-autocomplete bin/terminus');
// d($autocomplete);
file_put_contents('assets/autocomplete.txt', $autocomplete);
} elseif ( strlen(shell_exec('which symfony-autocomplete')) > 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";
Copy link
Member

Choose a reason for hiding this comment

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

The project in question recommends composer global require, but we should not.

https://pantheon.io/blog/fixing-composer-global-command

Copy link
Member

Choose a reason for hiding this comment

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

Oh, never mind. bamarni/symfony-console-autocomplete has no dependencies, so it's actually safe to use it with composer global require.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, my assumption is that almost no one will ever run this, most people will get this via the CI generated Phar file. This will only be needed using Terminus via composer

exit(1);
}
54 changes: 54 additions & 0 deletions src/Commands/AutocompleteCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Pantheon\Terminus\Commands;

use Pantheon\Terminus\Exceptions\TerminusNotFoundException;
use Pantheon\Terminus\Helpers\LocalMachineHelper;

/**
* Class AutocompleteCommand
* @package Pantheon\Terminus\Commands
*/
class AutocompleteCommand extends TerminusCommand
{

/**
* Displays Terminus Autocomplete config
*
* @command autocomplete
*
* @usage Returns the shell autocomplete config.
*/
public function autocomplete()
{
return $this->retrieveList();
}

/**
* Return the filename.
*
* @return string
*/
protected function getFilename()
{
return $this->config->get('assets_dir') . "/autocomplete.txt";
Copy link
Contributor

Choose a reason for hiding this comment

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

This should go into the cache dir. The assets dir holds the ASCII art.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll adjust the location

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@TeslaDethray so my intent with this was to cache the autocomplete script so it could be included with the Phar instead of including all the libraries used to generate it. The cache dir looks like it's user specific, and wouldn't be bundled into the phar. Would it make sense to create a separate folder just for caching the autocomplete script?

}

/**
* 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.'
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be a different message if you are running Terminus via a PHAR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in theory the Phar should have the compiled/cached autocomplete script that's generated during the build process, this is for someone running the composer version

);
}
return $local_machine_helper->readFile($filename);
}
}
1 change: 1 addition & 0 deletions src/Terminus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down