-
Notifications
You must be signed in to change notification settings - Fork 47
/
acli
executable file
·110 lines (98 loc) · 3.68 KB
/
acli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env php
<?php
/**
* @file
* Acquia CLI command line front file.
*
* This is largely based on the default bin/console command that ships with a
* Symfony app. However, it's been modified to not rely on the Framework Bundle,
* which spares us from unnecessary dependencies such as the routing layer.
*
* ORCA does something similar.
*
* @see https://github.com/TravisCarden/stackoverflow-a-50356503
*/
namespace Acquia\Cli;
use Acquia\Cli\Command\Acsf\AcsfCommandFactory;
use Acquia\Cli\Command\Api\ApiCommandFactory;
use Acquia\Cli\Command\Api\ApiCommandHelper;
use Acquia\Cli\Exception\AcquiaCliException;
use Acquia\Cli\Helpers\LocalMachineHelper;
use Dotenv\Dotenv;
use SelfUpdate\SelfUpdateCommand;
use SelfUpdate\SelfUpdateManager;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL;
}
set_time_limit(0);
if (isset($_composer_autoload_path)) {
$loader = require $_composer_autoload_path;
}
else {
$autoload_locations = [
dirname(__DIR__) . '/vendor/autoload.php',
dirname(__DIR__) . '/../../autoload.php',
];
foreach ($autoload_locations as $autoload_location) {
if (file_exists($autoload_location)) {
$loader = require $autoload_location;
break;
}
}
}
if (!isset($loader)) {
throw new AcquiaCliException('Unable to find autoload.php');
}
// We must preload this class to prevent self-update command from breaking.
// @see https://github.com/acquia/cli/issues/234
$loader->loadClass('Symfony\Component\Console\Event\ConsoleTerminateEvent');
$input = new ArgvInput();
// On some environments (looking at you, Windows), HOME may not be set.
if (!getenv('HOME')) {
putenv('HOME=' . LocalMachineHelper::getHomeDir());
}
if (!getenv('ACLI_HOME')) {
putenv('ACLI_HOME=' . LocalMachineHelper::getConfigDir());
}
$kernel = new Kernel('prod', false);
// Handle a clear-kernel-cache pseudo command. This isn't implemented as a true console
// command because a stale or corrupted cache would render it unusable--
// precisely when it is needed.
if (in_array($input->getFirstArgument(), ['clear-kernel-cache', 'ckc'])) {
$filesystem = new Filesystem();
$kernel_cache_dir = $kernel->getCacheDir();
$filesystem->remove([$kernel_cache_dir]);
$filesystem->mkdir($kernel_cache_dir);
$filesystem->touch("$kernel_cache_dir/.gitkeep");
exit;
}
putenv('BUGSNAG_KEY=');
putenv('AMPLITUDE_KEY=');
putenv('ACLI_VERSION=dev-unknown');
$dotenv = Dotenv::createUnsafeMutable(__DIR__ . '/..');
$dotenv->safeLoad();
$kernel->boot();
$container = $kernel->getContainer();
if (!getenv('ACLI_REPO_ROOT')) {
putenv("ACLI_REPO_ROOT=" . LocalMachineHelper::getProjectDir());
}
/** @var Application $application */
$application = $container->get(Application::class);
/** @var OutputInterface $output */
$output = $container->get(OutputInterface::class);
/** @var ApiCommandHelper $helper */
$helper = $container->get(ApiCommandHelper::class);
$application->addCommands($helper->getApiCommands( __DIR__ . '/../assets/acquia-spec.json', 'api', $container->get(ApiCommandFactory::class)));
$application->addCommands($helper->getApiCommands( __DIR__ . '/../assets/acsf-spec.json', 'acsf', $container->get(AcsfCommandFactory::class)));
try {
/** @var SelfUpdateManager $selfUpdateManager*/
$selfUpdateManager = $container->get(SelfUpdateManager::class);
$application->add(new SelfUpdateCommand($selfUpdateManager));
}
catch (\UnexpectedValueException) {
// Do nothing for development builds.
}
$application->run($input, $output);