mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 00:50:18 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			76 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			76 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
class Mage_Console
 | 
						|
{
 | 
						|
    private $_args;
 | 
						|
    private $_action;
 | 
						|
    private $_actionOptions;
 | 
						|
    private $_environment;
 | 
						|
    
 | 
						|
    public function setArgs($args)
 | 
						|
    {
 | 
						|
        $this->_args = $args;
 | 
						|
        array_shift($this->_args);
 | 
						|
    }
 | 
						|
    
 | 
						|
    public function parse()
 | 
						|
    {
 | 
						|
        foreach ($this->_args as $argument) {
 | 
						|
            if ($argument == 'deploy') {
 | 
						|
                $this->_action = 'deploy';
 | 
						|
 | 
						|
            } else if ($argument == 'update') {
 | 
						|
                $this->_action = 'update';
 | 
						|
 | 
						|
            } else if (preg_match('/to:[\w]+/i', $argument)) {
 | 
						|
                $this->_environment = str_replace('to:', '', $argument);
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
    
 | 
						|
    public function getAction()
 | 
						|
    {
 | 
						|
        return $this->_action;
 | 
						|
    }
 | 
						|
    
 | 
						|
    public function getEnvironment()
 | 
						|
    {
 | 
						|
        return $this->_environment;
 | 
						|
    }
 | 
						|
    
 | 
						|
    public static function output($message, $tabs = 1, $newLine = true)
 | 
						|
    {
 | 
						|
        $output = str_repeat("\t", $tabs)
 | 
						|
                . Mage_Console_Colors::color($message)
 | 
						|
                . ($newLine ? PHP_EOL : '');
 | 
						|
 | 
						|
        echo $output;
 | 
						|
    }
 | 
						|
    
 | 
						|
    public static function executeCommand($command)
 | 
						|
    {
 | 
						|
        ob_start();
 | 
						|
        system($command . ' 2>&1', $return);
 | 
						|
        $log = ob_get_clean();
 | 
						|
 | 
						|
        return !$return;
 | 
						|
    }
 | 
						|
    
 | 
						|
    public function run()
 | 
						|
    {       
 | 
						|
        $config = new Mage_Config;
 | 
						|
        $config->loadEnvironment($this->getEnvironment());
 | 
						|
        $config->loadSCM();
 | 
						|
 | 
						|
        switch ($this->getAction()) {
 | 
						|
            case 'deploy':
 | 
						|
                $task = new Mage_Task_Deploy;
 | 
						|
                $task->run($config);
 | 
						|
                break;
 | 
						|
 | 
						|
            case 'update';
 | 
						|
                $task = new Mage_Task_Update;
 | 
						|
                $task->run($config);
 | 
						|
                break;
 | 
						|
        }
 | 
						|
    }
 | 
						|
} |