think\console\Input::getOption PHP Method

getOption() public method

获取选项值
public getOption ( string $name ) : mixed
$name string 选项名称
return mixed
    public function getOption($name)
    {
        if (!$this->definition->hasOption($name)) {
            throw new \InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
        }
        return isset($this->options[$name]) ? $this->options[$name] : $this->definition->getOption($name)->getDefault();
    }

Usage Example

Exemplo n.º 1
0
 protected function execute(Input $input, Output $output)
 {
     if (!is_dir(RUNTIME_PATH . 'schema')) {
         @mkdir(RUNTIME_PATH . 'schema', 0755, true);
     }
     if ($input->hasOption('module')) {
         $module = $input->getOption('module');
         // 读取模型
         $list = scandir(APP_PATH . $module . DS . 'model');
         $app = App::$namespace;
         foreach ($list as $file) {
             if ('.' == $file || '..' == $file) {
                 continue;
             }
             $class = '\\' . $app . '\\' . $module . '\\model\\' . pathinfo($file, PATHINFO_FILENAME);
             $this->buildModelSchema($class);
         }
         $output->writeln('<info>Succeed!</info>');
         return;
     } else {
         if ($input->hasOption('table')) {
             $table = $input->getOption('table');
             if (!strpos($table, '.')) {
                 $dbName = Db::getConfig('database');
             }
             $tables[] = $table;
         } elseif ($input->hasOption('db')) {
             $dbName = $input->getOption('db');
             $tables = Db::getTables($dbName);
         } elseif (!\think\Config::get('app_multi_module')) {
             $app = App::$namespace;
             $list = scandir(APP_PATH . 'model');
             foreach ($list as $file) {
                 if ('.' == $file || '..' == $file) {
                     continue;
                 }
                 $class = '\\' . $app . '\\model\\' . pathinfo($file, PATHINFO_FILENAME);
                 $this->buildModelSchema($class);
             }
             $output->writeln('<info>Succeed!</info>');
             return;
         } else {
             $tables = Db::getTables();
         }
     }
     $db = isset($dbName) ? $dbName . '.' : '';
     $this->buildDataBaseSchema($tables, $db);
     $output->writeln('<info>Succeed!</info>');
 }
All Usage Examples Of think\console\Input::getOption