@@ -246,7 +246,7 @@ public function parseOutOurOptions($argv, $optionDefaultValues)
246
246
*/
247
247
public function separateProjectsFromArgs ($ argv , $ options )
248
248
{
249
- $ cgrCommands = array ('info ' , 'require ' , 'update ' , 'remove ' );
249
+ $ cgrCommands = array ('info ' , 'require ' , 'update ' , 'remove ' , ' extend ' );
250
250
$ command = 'require ' ;
251
251
$ composerArgs = array ();
252
252
$ projects = array ();
@@ -276,6 +276,8 @@ public function separateProjectsFromArgs($argv, $options)
276
276
} elseif ($ arg == 'global ' ) {
277
277
// Make note if we see the 'global' command.
278
278
$ globalMode = true ;
279
+ } elseif ($ command == 'extend ' ) {
280
+ $ projects [$ arg ] = true ;
279
281
} else {
280
282
// If we see any command other than 'global [require|update|remove]',
281
283
// then we will pass *all* of the arguments through to
@@ -318,6 +320,33 @@ public function requireCommand($execPath, $composerArgs, $projects, $options)
318
320
return array_merge ($ stabilityCommands , $ requireCommands );
319
321
}
320
322
323
+ public function extendCommand ($ execPath , $ composerArgs , $ projects , $ options )
324
+ {
325
+ $ projectToExtend = $ this ->getProjectToExtend ($ projects );
326
+ if (!$ projectToExtend ) {
327
+ print "No command to extend specified \n" ;
328
+ exit (1 );
329
+ }
330
+ array_shift ($ projects );
331
+
332
+ $ options ['base-dir ' ] .= '/ ' . $ projectToExtend ;
333
+ $ options ['extend-mode ' ] = true ;
334
+ if (!is_dir ($ options ['base-dir ' ])) {
335
+ print "Project $ projectToExtend not found; try 'cgr require' first \n" ;
336
+ exit (1 );
337
+ }
338
+
339
+ return $ this ->requireCommand ($ execPath , $ composerArgs , $ projects , $ options );
340
+ }
341
+
342
+ protected function getProjectToExtend ($ projects )
343
+ {
344
+ $ keys = array_keys ($ projects );
345
+ $ project = array_shift ($ keys );
346
+
347
+ return $ project ;
348
+ }
349
+
321
350
/**
322
351
* General command handler.
323
352
*
@@ -335,10 +364,11 @@ public function generalCommand($composerCommand, $execPath, $composerArgs, $proj
335
364
{
336
365
$ globalBaseDir = $ options ['base-dir ' ];
337
366
$ binDir = $ options ['bin-dir ' ];
367
+ $ extendMode = !empty ($ options ['extend-mode ' ]);
338
368
$ env = array ("COMPOSER_BIN_DIR " => $ binDir );
339
369
$ result = array ();
340
370
foreach ($ projects as $ project => $ version ) {
341
- $ installLocation = "$ globalBaseDir/ $ project " ;
371
+ $ installLocation = $ extendMode ? $ globalBaseDir : "$ globalBaseDir/ $ project " ;
342
372
$ projectWithVersion = $ this ->projectWithVersion ($ project , $ version );
343
373
$ commandToExec = $ this ->buildGlobalCommand ($ composerCommand , $ execPath , $ composerArgs , $ projectWithVersion , $ env , $ installLocation );
344
374
$ result [] = $ commandToExec ;
0 commit comments