This repository was archived by the owner on Apr 27, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathBuildResourcesGetCommand.php
More file actions
74 lines (61 loc) · 2.73 KB
/
Copy pathBuildResourcesGetCommand.php
File metadata and controls
74 lines (61 loc) · 2.73 KB
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
<?php
namespace Platformsh\Cli\Command\Resources\Build;
use Platformsh\Cli\Command\Resources\ResourcesCommandBase;
use Platformsh\Cli\Service\Table;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class BuildResourcesGetCommand extends ResourcesCommandBase
{
protected $tableHeader = [
'cpu' => 'CPU',
'memory' => 'Memory (MB)',
];
protected function configure()
{
$this->setName('resources:build:get')
->setAliases(['build-resources:get', 'build-resources'])
->setDescription('View the build resources of a project')
->addProjectOption();
Table::configureInput($this->getDefinition(), $this->tableHeader);
if ($this->config()->has('service.resources_help_url')) {
$this->setHelp('For more information on managing resources, see: <info>' . $this->config()->get('service.resources_help_url') . '</info>');
}
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->validateInput($input);
if (!$this->api()->supportsSizingApi($this->getSelectedProject())) {
$this->stdErr->writeln(
sprintf(
'The flexible resources API is not enabled for the project %s.\n
The function you attempted to use is not available on fixed plans.\n
Please refer to the Fixed documentation: https://fixed.docs.upsun.com/
', $this->api()->getProjectLabel($this->getSelectedProject(), 'comment')
)
);
return 1;
}
$project = $this->getSelectedProject();
$settings = $project->getSettings();
/** @var Table $table */
$table = $this->getService('table');
$isOriginalCommand = $input instanceof ArgvInput;
if (!$table->formatIsMachineReadable() && $isOriginalCommand) {
$this->stdErr->writeln(sprintf('Build resources for the project %s:', $this->api()->getProjectLabel($this->getSelectedProject())));
}
$rows = [
[
'cpu' => $settings['build_resources']['cpu'],
'memory' => $settings['build_resources']['memory'],
],
];
$table->render($rows, $this->tableHeader);
if (!$table->formatIsMachineReadable() && $isOriginalCommand) {
$executable = $this->config()->get('application.executable');
$this->stdErr->writeln('');
$this->stdErr->writeln(sprintf('Configure resources by running: <info>%s resources:build:set</info>', $executable));
}
return 0;
}
}