Skip to content

Commit 664391e

Browse files
committed
Add support for renaming services
Fix changing main container name used for service identification Fix hard coded phpstorm usage in edit command
1 parent c806847 commit 664391e

File tree

5 files changed

+44
-14
lines changed

5 files changed

+44
-14
lines changed

src/Commands/Config/ChangeConfigCommand.php

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,24 @@ private function removeServiceDependency(Project $project, string $library, arra
195195
return true;
196196
}
197197

198+
private function renameService(Project $project, string $library, array $values): bool
199+
{
200+
if (!isset($values[0]) || empty($values[0])) {
201+
return false;
202+
}
203+
204+
/** @var Service $service */
205+
$service = $project->services()->get($library);
206+
207+
$project->services()->list()->unset($library);
208+
209+
$service->rename($values[0]);
210+
211+
$project->services()->add($service);
212+
213+
return true;
214+
}
215+
198216
private function addTemplate(Project $project, string $library, array $values): bool
199217
{
200218
foreach ($values as $template) {
@@ -225,16 +243,18 @@ private function removeTemplate(Project $project, string $library, array $values
225243
private const SERVICE_CONTAINER = 'service:container:name';
226244
private const SERVICE_DEPENDENCY_ADD = 'service:dependency:add';
227245
private const SERVICE_DEPENDENCY_REMOVE = 'service:dependency:remove';
246+
private const SERVICE_RENAME = 'service:rename';
228247
private const PROJECT_TEMPLATE_ADD = 'template:add';
229248
private const PROJECT_TEMPLATE_REMOVE = 'template:remove';
230249

231250
private $options = [
232251
self::GIT_REMOTE => 'Set the remote repository for the project/library/service',
233252
self::PROJECT_DOCKER_NAME => 'Set the docker compose project name',
234253
self::PROJECT_DOCKER_NETWORK => 'Set the docker shared network name',
235-
self::SERVICE_CONTAINER => 'Change the services container name',
254+
self::SERVICE_CONTAINER => 'Change the name of the services main container (used for detection)',
236255
self::SERVICE_DEPENDENCY_ADD => 'Add a dependency to the service',
237256
self::SERVICE_DEPENDENCY_REMOVE => 'Remove a dependency from the service',
257+
self::SERVICE_RENAME => 'Rename an existing services alias',
238258
self::PROJECT_TEMPLATE_ADD => 'Change a project template source (specify as type:name:source)',
239259
self::PROJECT_TEMPLATE_REMOVE => 'Remove a project template',
240260
];
@@ -243,9 +263,10 @@ private function removeTemplate(Project $project, string $library, array $values
243263
self::GIT_REMOTE => 'Enter the full remote git address in the form git://: ',
244264
self::PROJECT_DOCKER_NAME => 'Enter the name to be used as the project prefix: ',
245265
self::PROJECT_DOCKER_NETWORK => 'Enter the network name that services communicate with: ',
246-
self::SERVICE_CONTAINER => 'Enter the application containers name without prefix: ',
247-
self::SERVICE_DEPENDENCY_ADD => 'Specify dependencies as a comma separated string: ',
248-
self::SERVICE_DEPENDENCY_REMOVE => 'Remove the services (separate with a comma): ',
266+
self::SERVICE_CONTAINER => 'Enter the name of the main container. This must be a valid docker-compose container name: ',
267+
self::SERVICE_DEPENDENCY_ADD => 'Specify dependencies to add as a comma separated string: ',
268+
self::SERVICE_DEPENDENCY_REMOVE => 'Specify dependencies to remove as a comma separated string: ',
269+
self::SERVICE_RENAME => 'Enter the new service alias (this is only the name used in spm): ',
249270
self::PROJECT_TEMPLATE_ADD => 'Add or set the template source ([library|service]:name:source) : ',
250271
self::PROJECT_TEMPLATE_REMOVE => 'Remove templates (separate with a comma) from the project: ',
251272
];
@@ -254,9 +275,10 @@ private function removeTemplate(Project $project, string $library, array $values
254275
self::GIT_REMOTE => 'AllLibraries',
255276
self::PROJECT_DOCKER_NAME => 'Project',
256277
self::PROJECT_DOCKER_NETWORK => 'Project',
257-
self::SERVICE_CONTAINER => 'Project',
278+
self::SERVICE_CONTAINER => 'Services',
258279
self::SERVICE_DEPENDENCY_ADD => 'Services',
259280
self::SERVICE_DEPENDENCY_REMOVE => 'Services',
281+
self::SERVICE_RENAME => 'Services',
260282
self::PROJECT_TEMPLATE_ADD => 'Project',
261283
self::PROJECT_TEMPLATE_REMOVE => 'Project',
262284
];
@@ -268,6 +290,7 @@ private function removeTemplate(Project $project, string $library, array $values
268290
self::SERVICE_CONTAINER => 'setServiceContainer',
269291
self::SERVICE_DEPENDENCY_ADD => 'addServiceDependency',
270292
self::SERVICE_DEPENDENCY_REMOVE => 'removeServiceDependency',
293+
self::SERVICE_RENAME => 'renameService',
271294
self::PROJECT_TEMPLATE_ADD => 'addTemplate',
272295
self::PROJECT_TEMPLATE_REMOVE => 'removeTemplate',
273296
];
@@ -297,7 +320,7 @@ private function getLibraries(Project $project): MutableCollection
297320
})
298321
->sortByValue()
299322
->values()
300-
;
323+
;
301324
}
302325

303326
private function getServices(Project $project): MutableCollection
@@ -309,7 +332,7 @@ private function getServices(Project $project): MutableCollection
309332
})
310333
->sortByValue()
311334
->values()
312-
;
335+
;
313336
}
314337

315338
private function getAllLibraries(Project $project): MutableCollection
@@ -318,6 +341,6 @@ private function getAllLibraries(Project $project): MutableCollection
318341
->getLibraries($project)
319342
->merge($this->getServices($project))
320343
->prepend('project')
321-
;
344+
;
322345
}
323346
}

src/Commands/OpenLibraryCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected function configure()
2727
{
2828
$this
2929
->setName('open')
30-
->setDescription('Open the specified library / service in PhpStorm')
30+
->setDescription('Open the specified library / service in the configured IDE')
3131
->addArgument('library', InputArgument::OPTIONAL, 'The name of the library or service')
3232
;
3333
}
@@ -46,7 +46,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
4646

4747
$program = $_SERVER['SOMNAMBULIST_EDITOR'] ?? 'phpstorm';
4848

49-
$this->tools()->info('opening <info>%s</info> in PhpStorm', $resource->name());
49+
$this->tools()->info('opening <info>%s</info> in <info>%s</info>', $resource->name(), $program);
5050
$this->tools()->execute(sprintf('%s %s', $program, $resource->installPath()), $resource->installPath());
5151
$this->tools()->newline();
5252

src/Commands/Projects/EditProjectCommand.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected function configure()
2626
$this
2727
->setName('project:edit')
2828
->setAliases(['edit'])
29-
->setDescription('Open the config folder with PhpStorm for the current project')
29+
->setDescription('Open the config folder with the configured editor for the current project')
3030
;
3131
}
3232

@@ -38,8 +38,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
3838

3939
$this->tools()->info('active project is <info>%s</info>', $project->name());
4040

41-
$this->tools()->info('opening project configuration in PhpStorm');
42-
$this->tools()->execute(sprintf('phpstorm %s', $project->configPath()), $project->configPath());
41+
$program = $_SERVER['SOMNAMBULIST_EDITOR'] ?? 'phpstorm';
42+
43+
$this->tools()->info('opening project configuration in <info>%s</info>', $program);
44+
$this->tools()->execute(sprintf('%s %s', $program, $project->configPath()), $project->configPath());
4345
$this->tools()->newline();
4446

4547
return 0;

src/Commands/Services/CreateServiceCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9090
$template = $this->tools()->choose('Which template would you like to use?', $this->config->availableTemplates('service'));
9191
}
9292
if (!$container) {
93-
$container = $this->tools()->ask('What will be the name of your application container? [e.g: example-app] ');
93+
$container = $this->tools()->ask('What will be the name of your application container? [e.g: proxy, kibana, example-app] ');
9494
}
9595
if (1 === $template = $this->getTemplate($template)) {
9696
return 1;

src/Models/AbstractLibrary.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public function setRepository(string $repository): void
6262
$this->repository = $repository;
6363
}
6464

65+
public function rename(string $name): void
66+
{
67+
$this->name = $name;
68+
}
69+
6570
abstract public function installPath(): string;
6671

6772
public function isInstalled(): bool

0 commit comments

Comments
 (0)