Example #1
0
File: One.php Project: crodas/cli
 /**
  *  @CliPlugin One
  *  @CliPlugin Crontab
  */
 public function main(zCallable $function, $input, $output)
 {
     $args = $function->getOne('one,crontab')->getArgs();
     $lock = File::generateFilePath('lock', $function->getName());
     if (!empty($args)) {
         $lock = $args[0];
     }
     if (filesize($lock) > 0) {
         $pid = trim(file_get_contents($lock));
         if (posix_getsid($pid) !== false) {
             throw new RuntimeException("Process {$function->getName()}() is still running");
         }
     }
     File::write($lock, getmypid());
 }
Example #2
0
File: Cli.php Project: crodas/cli
 protected function registerCommand(Application $app, zCallable $function, array $opts)
 {
     foreach ($function->get('cli') as $ann) {
         $args = array_values($ann->getArgs());
         if (empty($args)) {
             continue;
         }
         $question = $app->getHelperSet()->get('question');
         $app->register($args[0])->setDescription(!empty($args[1]) ? $args[1] : $args[0])->setDefinition($opts)->setCode($this->wrapper($function, $question));
     }
 }