/** * Says hello to someone * * @arg name The name of the person to say hello to */ public function executeHello(array $args, array $options = array()) { $name = 'unknown'; if (empty($args)) { $dialog = new Dialog($this->console); $name = $dialog->ask('What is your name?', $name); } else { $name = $args[0]; } $this->writeln(sprintf('hello %s!', $name)); }
public function executeImport(array $args = array(), array $options = array()) { $databases = $this->getConfig('$.mysql.databases'); if (isset($args[0]) && !isset($args[1]) && !empty($databases)) { if (count($databases) == 1) { $databases = array($databases[0] => $args[0]); } else { $dialog = new ConsoleKit\Widgets\Dialog($this->getConsole()); $choice = $dialog->ask("Choose a database :\n- " . implode("\n- ", $databases) . "\nEnter a database name:", $databases[0]); $databases = array($choice => $args[0]); } } else { if (isset($args[0]) && isset($args[1])) { $databases = array($args[1] => $args[0]); } else { $databases = array(); } } if (!empty($databases)) { foreach ($databases as $database => $file) { if (!file_exists($file)) { $this->writeln('File ' . $file . ' does not exist', ConsoleKit\Colors::YELLOW); } else { if (empty($database)) { $this->writeln('No database set', ConsoleKit\Colors::YELLOW); } else { $dialog = new ConsoleKit\Widgets\Dialog($this->getConsole()); if ($dialog->confirm('Are you sure you want to import ' . $file . ' into ' . $database . ' ?')) { $running = true; if (!($running = $this->isRunning($this->getPath($options['pid-file'])))) { $this->getConsole()->execute('mysql', array('daemon', 'start'), $options); } exec($this->getConfig('$.mysql.commands.mysql') . ' --user=root --password="******" ' . $this->buildParameters($options, 'socket') . ' ' . $database . ' < ' . $file); if (!$running) { $this->getConsole()->execute('mysql', array('daemon', 'stop'), $options); } $this->writeln('File ' . $file . ' imported to ' . $database, ConsoleKit\Colors::GREEN); } } } } } else { $this->writeln('Missing arguments', ConsoleKit\Colors::YELLOW); } }