Example #1
0
 /**
  * @param \Peanut\Console\Application $app
  * @param array                       $config
  */
 public function exec(\Peanut\Console\Application $app, array $config)
 {
     $name = $app->getArgument('container name');
     $command = $app->getArgument('*');
     $this->initMachine();
     $this->dockerSsh($name, $command);
 }
Example #2
0
 /**
  * @param \Peanut\Console\Application $app
  * @param array                       $config
  */
 public function exec(\Peanut\Console\Application $app, array $config)
 {
     $isFollow = $app->getOption('follow');
     $name = $app->getArgument('container name');
     $this->initMachine();
     $this->dockerLog($name, $isFollow);
 }
Example #3
0
 /**
  * @param \Peanut\Console\Application $app
  * @param array                       $config
  */
 public function exec(\Peanut\Console\Application $app, array $config)
 {
     $name = $app->getArgument('container name');
     $force = $app->getOption('force');
     $this->initMachine();
     $this->dockerRm($name, $force);
 }
Example #4
0
 /**
  * @param \Peanut\Console\Application $app
  * @param array                       $config
  */
 public function exec(\Peanut\Console\Application $app, array $config)
 {
     $isAll = $app->getOption('all');
     $config = $this->getConfig();
     $this->initMachine($config);
     echo PHP_EOL;
     $this->dockerLs($isAll);
 }
Example #5
0
 /**
  * @param \Peanut\Console\Application $app
  */
 public function execute(\Peanut\Console\Application $app)
 {
     $manager = new Manager($manifest = Manifest::loadFile('https://raw.githubusercontent.com/yejune/bootapp/master/manifest.json'));
     $result = $manager->update($app->getApplicationVersion(), true, true);
     if ($result) {
         $this->message('Update successful!');
     } else {
         $this->message('Already up-to-date.');
     }
 }
Example #6
0
 /**
  * @param \Peanut\Console\Application $app
  * @param array                       $config
  */
 public function exec(\Peanut\Console\Application $app, array $config)
 {
     $this->initMachine();
     $taskName = $app->getArgument('task name');
     $action = $app->getArgument('*');
     if (true === isset($config['tasks'])) {
         if (true === in_array($taskName, array_keys($config['tasks']))) {
             $this->dockerTask($config['tasks'][$taskName], $action);
         } else {
             throw new \Peanut\Console\Exception($taskName . ' not defined');
         }
     }
 }
Example #7
0
 /**
  * @param \Peanut\Console\Application $app
  * @param array                       $config
  */
 public function exec(\Peanut\Console\Application $app, array $config)
 {
     $this->process('sudo -v', ['print' => false]);
     $mode = $app->getOption('attach') ? 'attach' : 'detach';
     $ispull = $app->getOption('pull') ? true : false;
     if ('attach' == $mode) {
         if (false === function_exists('pcntl_fork')) {
             $mode = 'detach';
             echo \Peanut\Console\Color::text('attach mode is not support, start detach mode', 'red', '') . PHP_EOL;
         }
         $this->loop = \React\EventLoop\Factory::create();
         try {
             $this->run();
             $pcntl = new \MKraemer\ReactPCNTL\PCNTL($this->loop);
             $pcntl->on(SIGTERM, function () {
                 // kill
                 echo 'SIGTERM' . PHP_EOL;
                 exit;
             });
             $pcntl->on(SIGHUP, function () {
                 // logout
                 echo 'SIGHUP' . PHP_EOL;
                 exit;
             });
             $pcntl->on(SIGINT, function () {
                 // ctrl+c
                 echo 'Terminated by console' . PHP_EOL;
                 posix_kill(posix_getpid(), SIGUSR1);
                 echo $this->process('docker rm -f $(docker ps -q)');
                 exit;
             });
             echo 'Started as PID ' . getmypid() . PHP_EOL;
             $this->loop->run();
         } catch (\Exception $e) {
             throw new \Peanut\Console\Exception($e);
         }
     } else {
         $this->run($mode, $ispull);
         echo PHP_EOL;
         $this->dockerLs();
     }
 }
Example #8
0
 /**
  * @param \Peanut\Console\Application $app
  * @param array                       $config
  */
 public function exec(\Peanut\Console\Application $app, array $config)
 {
     $name = $app->getArgument('container name');
     $this->initMachine();
     $this->dockerInspect($name);
 }
Example #9
0
 /**
  * @param \Peanut\Console\Application $app
  */
 public function configuration(\Peanut\Console\Application $app)
 {
     $app->argument('target');
 }
Example #10
0
 /**
  * @param  \Peanut\Console\Application $app
  * @return mixed
  */
 public function execute(\Peanut\Console\Application $app)
 {
     $this->config = $this->getConfig();
     $this->verbose = $app->getOption('verbose');
     return $this->exec($app, $this->config);
 }
Example #11
0
 /**
  * @param  \Peanut\Console\Application $app
  * @return mixed
  */
 public function __construct(\Peanut\Console\Application $app)
 {
     $applicationName = $app->getApplicationName();
     //echo 'error hint'.PHP_EOL;
     $handlers = $app->handlers;
     usort($handlers, function ($a, $b) {
         if ($a->result['cnt'] == $b->result['cnt']) {
             //                return $a['more'] > $b['more'];
         }
         return $a->result['cnt'] < $b->result['cnt'];
     });
     //print_r($handlers);
     $helper = $handlers[0];
     $handlers = $app->handlers;
     //print_r($app->handlers);
     echo $helper->result['error'] . PHP_EOL . PHP_EOL;
     $tmp = $app->matching['cnt'];
     $s = $helper->result['cmd'];
     echo 'Usage :' . PHP_EOL;
     foreach ($handlers as $path => $helper) {
         $p = '#^' . preg_quote($s) . '\\\\([^\\\\]+)' . '$#';
         $p2 = '#^' . preg_quote($s) . '$' . '$#';
         if (preg_match($p, $helper->path) || preg_match($p2, $helper->path)) {
             $chk = true;
         } else {
             $chk = false;
         }
         //echo PHP_EOL.$p.' '.($helper->path);
         if ($chk) {
             $optIndex = 0;
             $optArr = [];
             $prt = [];
             $prt[] = '   ' . $applicationName;
             //print_r($helper->result);
             foreach ($helper->map as $arg) {
                 if (true === is_array($arg)) {
                     $tmp2 = [];
                     //print_r($helper);
                     foreach ($arg as $kkk => $vvv) {
                         $tmp2[] = '-' . $vvv['alias'] . ', ' . $kkk;
                     }
                     $prt[] = '[' . implode('|', $tmp2) . ']';
                     $optIndex++;
                     //$prt[]             = '[OPTIONS'.$optIndex.']';
                     $optArr[$optIndex] = $arg;
                 } elseif ('[' == $arg['0']) {
                     $prt[] = strtoupper($arg);
                 } else {
                     $prt[] = $arg;
                 }
             }
             echo PHP_EOL;
             echo implode(' ', $prt);
         }
     }
     /*
             echo PHP_EOL;
             echo PHP_EOL;
     
             foreach ($handlers as $path => $helper) {
                 $p = '#^'.preg_quote($s).'\\\([^\\\]+)'.'$#';
     
     //print_r([$p, $path]);
                 if (preg_match($p, $helper->path)) {
                     $optIndex = 0;
                     $optArr   = [];
                     $prt      = [];
                     $prt[]    = 'Usage';
                     $prt[]    = 'bootapp';
                     foreach ($helper->map as $arg) {
                         if (true === is_array($arg)) {
                             $optIndex++;
                             $prt[]             = '[Options'.$optIndex.']';
                             $optArr[$optIndex] = $arg;
                         } elseif ('[' == $arg['0']) {
                             $prt[] = strtoupper($arg);
                         } else {
                             $prt[] = $arg;
                         }
                     }
     
                     foreach ($optArr as $key => $arr) {
                         echo 'Options'.$key.' :'.PHP_EOL;
                         foreach ($arr as $k => $v) {
                             echo '   '.str_pad($k, 20, ' ', STR_PAD_RIGHT).'ddddd'.PHP_EOL;
                         }
     
                         echo PHP_EOL;
                     }
                 }
             }
     */
     echo PHP_EOL;
     //print_r($app);
 }