-
Notifications
You must be signed in to change notification settings - Fork 196
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
base: 2.x
Are you sure you want to change the base?
Autocomplete #2023
Changes from all commits
3db247f
c7ba991
7d74a8d
71822e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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"; | ||
exit(1); | ||
} |
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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll adjust the location There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.There was a problem hiding this comment.
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