示例#1
0
 function error($error)
 {
     if (!$error) {
         return;
     }
     if (is_string($error) && isset($this->upgrader->strings[$error])) {
         $error = $this->upgrader->strings[$error];
     }
     // TODO: show all errors, not just the first one
     \Terminus::warning($error);
 }
示例#2
0
 protected function success_or_failure($r)
 {
     list($type, $msg) = $r;
     if ('success' == $type) {
         \Terminus::success($msg);
         $status = 0;
     } else {
         \Terminus::warning($msg);
         $status = 1;
     }
     return $status;
 }
示例#3
0
 /**
  * @param array The raw CLI arguments
  * @return array The list of found items
  */
 public function get_many($args)
 {
     $items = array();
     foreach ($args as $arg) {
         $item = $this->get($arg);
         if ($item) {
             $items[] = $item;
         } else {
             \Terminus::warning(sprintf($this->msg, $arg));
         }
     }
     return $items;
 }
示例#4
0
 /**
  * @return array list of invalid $assoc_args keys to unset
  */
 private function validate_args($args, $assoc_args, $extra_args)
 {
     $synopsis = $this->get_synopsis();
     if (!$synopsis) {
         return array();
     }
     $validator = new \Terminus\SynopsisValidator($synopsis);
     $cmd_path = implode(' ', get_path($this));
     foreach ($validator->get_unknown() as $token) {
         \Terminus::warning(sprintf("The `%s` command has an invalid synopsis part: %s", $cmd_path, $token));
     }
     if (!$validator->enough_positionals($args)) {
         $this->show_usage();
         exit(1);
     }
     if ($this->name != 'help') {
         $invalid = $validator->invalid_positionals($args);
         if ($invalid) {
             \Terminus::error("Invalid positional value: {$invalid}");
         }
     }
     $unknown_positionals = $validator->unknown_positionals($args);
     if (!empty($unknown_positionals)) {
         \Terminus::error('Too many positional arguments: ' . implode(' ', $unknown_positionals));
     }
     list($errors, $to_unset) = $validator->validate_assoc(array_merge(\Terminus::get_config(), $extra_args, $assoc_args));
     foreach ($validator->unknown_assoc($assoc_args) as $key) {
         $errors['fatal'][] = "unknown --{$key} parameter";
     }
     if (!empty($errors['fatal'])) {
         $out = 'Parameter errors:';
         foreach ($errors['fatal'] as $error) {
             $out .= "\n " . $error;
         }
         \Terminus::error($out);
     }
     array_map('\\Terminus::warning', $errors['warning']);
     return $to_unset;
 }