Skip to content

Commit f77d6f7

Browse files
Add an 'extend' command. (#34)
1 parent cdb316a commit f77d6f7

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

src/Application.php

+32-2
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public function parseOutOurOptions($argv, $optionDefaultValues)
246246
*/
247247
public function separateProjectsFromArgs($argv, $options)
248248
{
249-
$cgrCommands = array('info', 'require', 'update', 'remove');
249+
$cgrCommands = array('info', 'require', 'update', 'remove', 'extend');
250250
$command = 'require';
251251
$composerArgs = array();
252252
$projects = array();
@@ -276,6 +276,8 @@ public function separateProjectsFromArgs($argv, $options)
276276
} elseif ($arg == 'global') {
277277
// Make note if we see the 'global' command.
278278
$globalMode = true;
279+
} elseif ($command == 'extend') {
280+
$projects[$arg] = true;
279281
} else {
280282
// If we see any command other than 'global [require|update|remove]',
281283
// then we will pass *all* of the arguments through to
@@ -318,6 +320,33 @@ public function requireCommand($execPath, $composerArgs, $projects, $options)
318320
return array_merge($stabilityCommands, $requireCommands);
319321
}
320322

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+
321350
/**
322351
* General command handler.
323352
*
@@ -335,10 +364,11 @@ public function generalCommand($composerCommand, $execPath, $composerArgs, $proj
335364
{
336365
$globalBaseDir = $options['base-dir'];
337366
$binDir = $options['bin-dir'];
367+
$extendMode = !empty($options['extend-mode']);
338368
$env = array("COMPOSER_BIN_DIR" => $binDir);
339369
$result = array();
340370
foreach ($projects as $project => $version) {
341-
$installLocation = "$globalBaseDir/$project";
371+
$installLocation = $extendMode ? $globalBaseDir : "$globalBaseDir/$project";
342372
$projectWithVersion = $this->projectWithVersion($project, $version);
343373
$commandToExec = $this->buildGlobalCommand($composerCommand, $execPath, $composerArgs, $projectWithVersion, $env, $installLocation);
344374
$result[] = $commandToExec;

0 commit comments

Comments
 (0)