public function run() { include getcwd() . '/bootstrap.php'; if (preg_match('#^\\p{Lu}#u', $this->config['name']) === 0) { echo "Error: parameter name must be camel-case. At a minimum, it must start with a capital letter.\n"; \Lucid\Task\Container::run('usage', [static::$trigger]); exit; } $this->config['meta'] = new \Lucid\Library\Metabase\Metabase(\ORM::get_db()); if (is_null($this->config['table']) === true) { $this->config['table'] = $this->config['name']; } $this->config['columns'] = $this->config['meta']->getColumns($this->config['table']); $this->config['keys'] = ['name' => $this->config['name'], 'table' => $this->config['table'], 'id_type' => $this->config['columns'][0]['type'], 'id' => $this->config['columns'][0]['name'], 'first_string_col' => null, 'title' => $this->config['name']]; foreach ($this->config['columns'] as $column) { if ($column['type'] == 'string' && is_null($this->config['keys']['first_string_col']) === true) { $this->config['keys']['first_string_col'] = $column['name']; } } # we always run all *BuildKeys methods in case a later *BuildFile function relies on a key built by # a component not selected for building $this->modelBuildKeys(); $this->viewBuildKeys(); $this->controllerBuildKeys(); $this->helperBuildKeys(); $this->rulesetBuildKeys(); $this->testBuildKeys(); $this->dictionaryBuildKeys(); if ($this->config['no-model'] === false) { echo "Building Model...\n"; $this->modelBuildFiles(); } if ($this->config['no-view'] === false) { echo "Building View...\n"; $this->viewBuildFiles(); } if ($this->config['no-controller'] === false) { echo "Building Controller...\n"; $this->controllerBuildFiles(); } if ($this->config['no-helper'] === false) { echo "Building Helper...\n"; $this->helperBuildFiles(); } if ($this->config['no-ruleset'] === false) { echo "Building Ruleset...\n"; $this->rulesetBuildFiles(); } if ($this->config['no-test'] === false) { echo "Building Test...\n"; $this->testBuildFiles(); } if ($this->config['no-dictionary'] === false) { echo "Building Dictionary...\n"; $this->dictionaryBuildFiles(); } echo "Complete.\n"; }
public function parseArguments(array $arguments) { if (count($arguments) > 0) { $parsedArguments = array_fill(0, count($arguments), false); } else { $parsedArguments = []; } # First, set defaults if they exist for all configs for ($i = 0; $i < count($this->parameters); $i++) { $this->config[$this->parameters[$i]->name] = $this->parameters[$i]->default; } $startOfLabeledParameters = 0; # Second, parse out unlabeled parameters. These must be in order, and must not start with --. for ($i = 0; $i < count($this->parameters); $i++) { if ($this->parameters[$i]->type == 'unlabeled') { if ($i < count($arguments) && strpos($arguments[$i], '--') !== 0) { $parsedArguments[$i] = true; $this->config[$this->parameters[$i]->name] = $arguments[$i]; } else { if ($this->parameters[$i]->optional === false) { echo "Error: No value found for mandatory parameter " . $this->parameters[$i]->name . "\n\n"; \Lucid\Task\Container::run('usage', [static::$trigger]); exit; } } } else { $startOfLabeledParameters = $i; $i = count($this->parameters); } } # Next, loop over the arguments and look for labeled parameters. for ($j = 0; $j < count($arguments); $j++) { # if the argument starts with a -- if (strpos($arguments[$j], '--') == 0) { # find this argument's equivalent paramenter for ($i = $startOfLabeledParameters; $i < count($this->parameters); $i++) { if ('--' . $this->parameters[$i]->name == $arguments[$j]) { if ($this->parameters[$i]->type == 'labeled') { $this->config[$this->parameters[$i]->name] = $arguments[$j + 1]; $parsedArguments[$j] = true; $parsedArguments[$j + 1] = true; } elseif ($this->parameters[$i]->type == 'flag') { $this->config[$this->parameters[$i]->name] = !$this->config[$this->parameters[$i]->name]; $parsedArguments[$j] = true; } } } } } /* for ($i=0; $i<count($this->parameters); $i++) { switch ($this->parameters[$i]->type) { case 'unlabeled': if (isset($arguments[$i]) === true) { $parsedArguments[$i] = true; $this->config[$this->parameters[$i]->name] = $arguments[$i]; } else { if ($this->parameters[$i]->optional === false) { echo("Parameter ".$this->parameters[$i]->name." is required.\n"); \Lucid\Task\Container::run('usage', [static::$trigger]); exit(); } $this->config[$this->parameters[$i]->name] = $this->parameters[$i]->default; } break; case 'labeled': $found = false; for ($j=0; $j< (count($arguments) - 1); $j++) { if ($arguments[$j] == '--'.$this->parameters[$i]->name) { $parsedArguments[$j] = true; $parsedArguments[$j + 1] = true; $this->config[$this->parameters[$i]->name] = $arguments[$j + 1]; $found = true; } } if (isset($this->config[$this->parameters[$i]->name]) === false) { $this->config[$this->parameters[$i]->name] = $this->parameters[$i]->default; } if ($found === true) { $i++; } break; case 'flag': $this->config[$this->parameters[$i]->name] = $this->parameters[$i]->default; for ($j=0; $j< (count($arguments) - 1); $j++) { if ($arguments[$j] == '--'.$this->parameters[$i]->name) { $parsedArguments[$j] = true; $this->config[$this->parameters[$i]->name] = (!$this->config[$this->parameters[$i]->name]); } } break; } } */ for ($i = 0; $i < count($parsedArguments); $i++) { if ($parsedArguments[$i] === false) { echo "Error: Unknown option " . $arguments[$i] . "\n\n"; \Lucid\Task\Container::run('usage', [static::$trigger]); exit; } } }