@@ -195,6 +195,24 @@ private function removeServiceDependency(Project $project, string $library, arra
195
195
return true ;
196
196
}
197
197
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
+
198
216
private function addTemplate (Project $ project , string $ library , array $ values ): bool
199
217
{
200
218
foreach ($ values as $ template ) {
@@ -225,16 +243,18 @@ private function removeTemplate(Project $project, string $library, array $values
225
243
private const SERVICE_CONTAINER = 'service:container:name ' ;
226
244
private const SERVICE_DEPENDENCY_ADD = 'service:dependency:add ' ;
227
245
private const SERVICE_DEPENDENCY_REMOVE = 'service:dependency:remove ' ;
246
+ private const SERVICE_RENAME = 'service:rename ' ;
228
247
private const PROJECT_TEMPLATE_ADD = 'template:add ' ;
229
248
private const PROJECT_TEMPLATE_REMOVE = 'template:remove ' ;
230
249
231
250
private $ options = [
232
251
self ::GIT_REMOTE => 'Set the remote repository for the project/library/service ' ,
233
252
self ::PROJECT_DOCKER_NAME => 'Set the docker compose project name ' ,
234
253
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) ' ,
236
255
self ::SERVICE_DEPENDENCY_ADD => 'Add a dependency to the service ' ,
237
256
self ::SERVICE_DEPENDENCY_REMOVE => 'Remove a dependency from the service ' ,
257
+ self ::SERVICE_RENAME => 'Rename an existing services alias ' ,
238
258
self ::PROJECT_TEMPLATE_ADD => 'Change a project template source (specify as type:name:source) ' ,
239
259
self ::PROJECT_TEMPLATE_REMOVE => 'Remove a project template ' ,
240
260
];
@@ -243,9 +263,10 @@ private function removeTemplate(Project $project, string $library, array $values
243
263
self ::GIT_REMOTE => 'Enter the full remote git address in the form git://: ' ,
244
264
self ::PROJECT_DOCKER_NAME => 'Enter the name to be used as the project prefix: ' ,
245
265
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): ' ,
249
270
self ::PROJECT_TEMPLATE_ADD => 'Add or set the template source ([library|service]:name:source) : ' ,
250
271
self ::PROJECT_TEMPLATE_REMOVE => 'Remove templates (separate with a comma) from the project: ' ,
251
272
];
@@ -254,9 +275,10 @@ private function removeTemplate(Project $project, string $library, array $values
254
275
self ::GIT_REMOTE => 'AllLibraries ' ,
255
276
self ::PROJECT_DOCKER_NAME => 'Project ' ,
256
277
self ::PROJECT_DOCKER_NETWORK => 'Project ' ,
257
- self ::SERVICE_CONTAINER => 'Project ' ,
278
+ self ::SERVICE_CONTAINER => 'Services ' ,
258
279
self ::SERVICE_DEPENDENCY_ADD => 'Services ' ,
259
280
self ::SERVICE_DEPENDENCY_REMOVE => 'Services ' ,
281
+ self ::SERVICE_RENAME => 'Services ' ,
260
282
self ::PROJECT_TEMPLATE_ADD => 'Project ' ,
261
283
self ::PROJECT_TEMPLATE_REMOVE => 'Project ' ,
262
284
];
@@ -268,6 +290,7 @@ private function removeTemplate(Project $project, string $library, array $values
268
290
self ::SERVICE_CONTAINER => 'setServiceContainer ' ,
269
291
self ::SERVICE_DEPENDENCY_ADD => 'addServiceDependency ' ,
270
292
self ::SERVICE_DEPENDENCY_REMOVE => 'removeServiceDependency ' ,
293
+ self ::SERVICE_RENAME => 'renameService ' ,
271
294
self ::PROJECT_TEMPLATE_ADD => 'addTemplate ' ,
272
295
self ::PROJECT_TEMPLATE_REMOVE => 'removeTemplate ' ,
273
296
];
@@ -297,7 +320,7 @@ private function getLibraries(Project $project): MutableCollection
297
320
})
298
321
->sortByValue ()
299
322
->values ()
300
- ;
323
+ ;
301
324
}
302
325
303
326
private function getServices (Project $ project ): MutableCollection
@@ -309,7 +332,7 @@ private function getServices(Project $project): MutableCollection
309
332
})
310
333
->sortByValue ()
311
334
->values ()
312
- ;
335
+ ;
313
336
}
314
337
315
338
private function getAllLibraries (Project $ project ): MutableCollection
@@ -318,6 +341,6 @@ private function getAllLibraries(Project $project): MutableCollection
318
341
->getLibraries ($ project )
319
342
->merge ($ this ->getServices ($ project ))
320
343
->prepend ('project ' )
321
- ;
344
+ ;
322
345
}
323
346
}
0 commit comments