diff --git a/src/Artistan/Workbench/Commands/DevelopCommand.php b/src/Artistan/Workbench/Commands/DevelopCommand.php index 862aae6..66ad6d2 100644 --- a/src/Artistan/Workbench/Commands/DevelopCommand.php +++ b/src/Artistan/Workbench/Commands/DevelopCommand.php @@ -37,7 +37,7 @@ class DevelopCommand extends Command { public function __construct() { parent::__construct(); - $this->benchhelper = new BenchHelper(); + $this->benchhelper = new BenchHelper($this); } /** diff --git a/src/Artistan/Workbench/Commands/InstallCommand.php b/src/Artistan/Workbench/Commands/InstallCommand.php index c00651d..0c60d16 100644 --- a/src/Artistan/Workbench/Commands/InstallCommand.php +++ b/src/Artistan/Workbench/Commands/InstallCommand.php @@ -37,7 +37,7 @@ class InstallCommand extends Command { public function __construct() { parent::__construct(); - $this->benchhelper = new BenchHelper(); + $this->benchhelper = new BenchHelper($this); } /** @@ -56,12 +56,11 @@ public function fire() } } foreach($packages as $name=>$package){ - echo "PACKAGE: $name\n"; + $this->info( "PACKAGE: $name" ); if(isset($package['git'])){ - $this->benchhelper->mkdir($name); $action = $this->benchhelper->getGit($name,$package); if($this->option('remote')){ - echo "remotes\n"; + $this->info( "remotes" ); $this->benchhelper->fetchRemotes($name,$package['remotes']); } if($this->option('merge')){ @@ -78,10 +77,10 @@ public function fire() } if($this->option('publishConfigs') || $action=='install'){ // this should not be done all the time, first time only (install) - $this->call('config:publish', array('argument' => $name, '--path' => 'workbench/'.$name.'/src/config')); + $this->call('config:publish', array('package' => $name, '--path' => 'workbench/'.$name.'/src/config')); } } - echo "============================\n\n\n"; + $this->info( "============================" ); } if(!$this->option('skipBower')){ $this->benchhelper->bower(); @@ -91,7 +90,6 @@ public function fire() // remove any packages from vendors directory that you are workbenching $this->benchhelper->composerVendorCleanup(array_keys($packages)); } - //$this->call('command:name', array('argument' => 'foo', '--option' => 'bar')); } /** @@ -115,7 +113,7 @@ protected function getOptions() { return array( array('destroy','d', InputOption::VALUE_NONE, 'Destroy current packages.'), - array('upstream','u', InputOption::VALUE_NONE, 'Fetch upstream.'), + array('remote','r', InputOption::VALUE_NONE, 'Fetch upstream.'), array('merge','m', InputOption::VALUE_OPTIONAL, 'Merge upstream into this branch.'), array('skipComposer','c', InputOption::VALUE_NONE, 'skip composer install/update'), array('skipBower','b', InputOption::VALUE_NONE, 'skip bower install/update'), diff --git a/src/Artistan/Workbench/Commands/LaunchCommand.php b/src/Artistan/Workbench/Commands/LaunchCommand.php index c5fa643..218e0aa 100644 --- a/src/Artistan/Workbench/Commands/LaunchCommand.php +++ b/src/Artistan/Workbench/Commands/LaunchCommand.php @@ -37,7 +37,7 @@ class LaunchCommand extends Command { public function __construct() { parent::__construct(); - $this->benchhelper = new BenchHelper(); + $this->benchhelper = new BenchHelper($this); } /** diff --git a/src/Artistan/Workbench/Helpers/BenchHelper.php b/src/Artistan/Workbench/Helpers/BenchHelper.php index 41cb21f..902b87b 100644 --- a/src/Artistan/Workbench/Helpers/BenchHelper.php +++ b/src/Artistan/Workbench/Helpers/BenchHelper.php @@ -2,15 +2,29 @@ namespace Artistan\Workbench\Helpers; class BenchHelper { + + + /** + * The console command object. + * + * @var InstallCommand + */ + protected $cmd = false; + + public function __construct(&$command){ + $this->cmd = $command; + } /** * destroys all workbench packages */ public function destroy($packages) { - echo "removing all configured packages\n"; + $this->cmd->info( "removing all configured packages" ); foreach($packages as $name){ // check if exists, also do not remove artistan/workbench cause I am working on it!!! - if(is_dir(base_path().'/workbench/'.$name) && $name!='artistan/workbench'){ - $this->exec('rm -rf '.base_path().'/workbench/'.$name); + while( is_dir( base_path().'/workbench/'.$name) && $name!='artistan/workbench' ){ + $path = explode('/',$name); + $this->exec( 'rm -rf '.base_path().'/workbench/'.$path[0] ); + clearstatcache ( true, base_path().'/workbench/'.$name ); } } } @@ -26,12 +40,13 @@ public function chStorage(){ * @throws Exception */ public function mkdir($name) { - echo "make dir $name\n"; + $this->cmd->info( "make dir $name" ); if(!empty($name)){ - //$this->call('command:name', array('argument' => 'foo', '--option' => 'bar')); if(is_dir(base_path().'/workbench/'.$name)){ + $this->cmd->error( "dir $name exists" );exit; return true; } else { + $this->cmd->error( "dir $name make" ); return mkdir(base_path().'/workbench/'.$name,0777,true); } } else { @@ -45,7 +60,7 @@ public function mkdir($name) { * @throws Exception */ public function composer($name='',$action='') { - echo "composer $name\n"; + $this->cmd->info( "composer $name" ); if(!empty($name) && !empty($action)){ if(is_dir(base_path().'/workbench/'.$name)){ chdir(base_path().'/workbench/'.$name); @@ -67,7 +82,7 @@ public function composer($name='',$action='') { * @param $packages */ public function composerVendorCleanup($packages) { - echo "composerVendorCleanup\n"; + $this->cmd->info( "composerVendorCleanup" ); foreach($packages as $name){ if(is_dir(base_path().'/vendor/'.$name)){ $this->exec('rm -rf '.base_path().'/vendor/'.$name); @@ -80,7 +95,7 @@ public function composerVendorCleanup($packages) { * @throws Exception */ public function bower($name='') { - echo "bower $name\n"; + $this->cmd->info( "bower $name" ); if(!empty($name)){ if(is_dir(base_path().'/workbench/'.$name)){ chdir(base_path().'/workbench/'.$name); @@ -106,9 +121,9 @@ public function bower($name='') { * @throws Exception */ public function getGit($name,array $package) { - echo "get git $name\n"; + $this->cmd->info( "get git $name" ); if(!empty($package['git'])){ - //$this->call('command:name', array('argument' => 'foo', '--option' => 'bar')); + $this->mkdir($name); chdir(base_path().'/workbench/'.$name); if(is_dir('.git')){ // just git pull @@ -131,8 +146,8 @@ public function getGit($name,array $package) { public function mergeRemote($merge){ if($merge){ $this->exec('git merge '.$merge); - } else { - echo "No remote merge requested\n"; + } else { + $this->error( "No remote merge requested" ); } } @@ -142,9 +157,8 @@ public function fetchRemotes($name,array $remotes){ } } public function getRemote($name,$remoteName,$location){ - echo "get git $name :: $remoteName\n"; + $this->cmd->info( "get git $name :: $remoteName" ); if(!empty($location)){ - //$this->call('command:name', array('argument' => 'foo', '--option' => 'bar')); chdir(base_path().'/workbench/'.$name); if(is_dir('.git')){ if(!$this->verifyRemote($name,$remoteName)){ @@ -161,7 +175,7 @@ public function getRemote($name,$remoteName,$location){ } } - public function verifyUpstream($name,$remoteName){ + public function verifyRemote($name,$remoteName){ chdir(base_path().'/workbench/'.$name); $str = shell_exec('git remote -v'); @@ -170,10 +184,11 @@ public function verifyUpstream($name,$remoteName){ // http://stackoverflow.com/questions/1281140/run-process-with-realtime-output-in-php /** - * @param string $cmd + * @param $cmd + * @param bool $echo */ public function exec($cmd,$echo=true){ - echo "Command: $cmd\n"; + $this->cmd->info( "Command: $cmd" ); if($echo){ $descriptor_spec = array( 0 => array("pipe", "r"), // stdin is a pipe that the child will read from @@ -194,7 +209,7 @@ public function exec($cmd,$echo=true){ } public function error($message,$exit=false){ - echo $message."\n"; + $this->cmd->info( "$message" ); if($exit){ exit; }