/** * Handle the command. * * @param Markdown $markdown */ public function handle(Markdown $markdown) { $this->command->info(strip_tags($markdown->transform(file_get_contents(base_path('LICENSE.md'))))); if (!$this->command->confirm('Do you agree to the provided license and terms of service?')) { $this->command->error('You must agree to the license and terms of service before continuing.'); exit; } }
/** * Handle the command. * * @param Filesystem $filesystem * @param Application $application * @return string */ public function handle(Filesystem $filesystem, Application $application) { $destination = $application->getResourcesPath('streams/lang'); if (is_dir($destination) && !$this->command->option('force')) { return $this->command->error("{$destination} already exists."); } $filesystem->copyDirectory(__DIR__ . '/../../../../resources/lang', $destination); $this->command->info("Published {$destination}"); }
/** * @param * @return string */ protected function askDatabaseUsername() { do { $user = $this->command->ask('Enter your database username', 'root'); if ($user == '') { $this->command->error('Database username is required'); } } while (!$user); return $user; }
/** * Handle the command. * * @param Filesystem $filesystem * @param Application $application * @return string */ public function handle(Filesystem $filesystem, Application $application) { $destination = $application->getResourcesPath('addons/' . $this->addon->getVendor() . '/' . $this->addon->getSlug() . '-' . $this->addon->getType() . '/views'); if (is_dir($destination) && !$this->command->option('force')) { $this->command->error("{$destination} already exists."); return; } $filesystem->copyDirectory($this->addon->getPath('resources/views'), $destination); $this->command->info("Published {$destination}"); }
/** * Handle the command. */ public function handle() { $this->data->put('ADMIN_USERNAME', $this->command->ask('Enter the desired username for the admin user', env('ADMIN_USERNAME', 'admin'))); $this->data->put('ADMIN_EMAIL', $this->command->ask('Enter the desired email for the admin user', env('ADMIN_EMAIL'))); // Validate email. if (!filter_var($this->data->get('ADMIN_EMAIL'), FILTER_VALIDATE_EMAIL)) { $this->command->error('You must provide a valid email for the admin.'); exit; } $this->data->put('ADMIN_PASSWORD', $this->command->ask('Enter the desired password for the admin user', env('ADMIN_PASSWORD'))); }
/** * Handle the command. * * @param Filesystem $filesystem * @param Application $application * @return string */ public function handle(Filesystem $filesystem, Application $application) { $destination = $application->getResourcesPath('.env'); if (!is_dir(dirname($destination))) { $filesystem->makeDirectory(dirname($destination), 0777, true, true); } if (is_file($destination) && !$this->command->option('force')) { return $this->command->error("{$destination} already exists."); } $filesystem->put($destination, '#EXAMPLE=foo'); $this->command->info("Published {$destination}"); }
/** * Handle the command. * * @param Filesystem $filesystem * @param Application $application * @return string */ public function handle(Filesystem $filesystem, Application $application) { $destination = $application->getResourcesPath('routes.php'); if (!is_dir(dirname($destination))) { $filesystem->makeDirectory(dirname($destination), 0777, true, true); } if (is_file($destination) && !$this->command->option('force')) { return $this->command->error("{$destination} already exists."); } $content = "<?php\n\n// Route::get('/', function () {\n// return view('welcome');\n// });\n"; $filesystem->put($destination, $content); $this->command->info("Published {$destination}"); }
/** * @param Command $console * @param $module * @param $name * @return mixed */ public function fire(Command $console, $module, $name) { $this->console = $console; $this->moduleName = Str::studly($module); $this->modelName = $name; if (!$this->module->has($this->moduleName)) { $console->error("Module [{$this->moduleName}] does not exists."); return false; } if ($this->exists()) { $message = "Model [{$this->modelName}] is already exists on '{$this->moduleName}' module."; return $console->error($message); } return $this->generate(); }
public function fire($arguments, $options) { $instanceId = array_get($arguments, CommandRules::INSTANCE_ID); $logFile = array_get($arguments, CommandRules::LOGFILE); $user = array_get($options, CommandRules::USER); $keyFile = array_get($options, CommandRules::KEY_FILE); $host = $this->aws->getPublicDNSFromInstanceId($instanceId); if (is_null($host)) { $this->command->error('Error: Could not find Host from Instance ID. Please try again.'); } else { $connection = $this->connectionFactory->createConnection($instanceId, $host, $user, $keyFile); $connection->run(array('tail -f ' . $logFile), function ($line) { $this->command->info($line); }); } }
/** * Display error message with date and message, and log it * @param string $message Error message to display & log */ public function error($message) { // Log message $this->log($message, 'error'); // Display message parent::error(date($this->timestampFormat) . ' ' . $message); }
/** * 输出错误信息,并记录日志 * * @param string $message * @param bool $isExit * @return void */ public function error($message, $isExit = true) { parent::error($message); Log::error($message, [__CLASS__]); if ($isExit) { exit; } }
/** * Publish assets form the specified module. * * @param $module */ protected function publishFromModule($module) { if (!$this->module->has($module)) { $this->console->error("Module [{$module}] does not exist."); exit; } $this->filesystem->copyDirectory($this->getPublishingPath($module), $this->getDestinationPath($module)); $this->console->info("Assets published from module : {$module}"); }
/** * @return string */ private function askForPasswordConfirmation() { do { $passwordConfirmation = $this->command->secret('Please confirm your password'); if ($passwordConfirmation == '') { $this->command->error('Password confirmation is required'); } } while (!$passwordConfirmation); return $passwordConfirmation; }
/** * Fire. * * @param Command $console * @param $module * @param $name * @return mixed|void */ public function fire(Command $console, $module, $name) { $this->console = $console; $this->moduleName = Str::studly($module); $this->name = $name; $this->Name = Str::studly($name); if ($this->module->has($this->moduleName)) { return $this->makeSeeder(); } $console->error("Module [{$this->moduleName}] does not exists."); }
/** * Generate the module. */ public function generate() { if ($this->module->has($name = $this->getName())) { $this->console->error("Module [{$name}] already exist!"); return; } $this->generateFolders(); $this->generateFiles(); $this->generateResources(); $this->console->info("Module [{$name}] created successfully."); }
public function renderCommandField(Command $command) { while (true) { $input = $command->secret($this->getConsoleLabel()); $validator = $this->getValidator($input); if ($validator->passes()) { return $input; } else { $command->error($validator->errors()->first()); } } }
public function fire($arguments, $options) { $envName = array_get($arguments, CommandRules::ENV); $logFile = array_get($arguments, CommandRules::LOGFILE); $user = array_get($options, CommandRules::USER); $keyFile = array_get($options, CommandRules::KEY_FILE); $hosts = $this->aws->getPublicDNSFromEBEnvironmentName($envName); if (count($hosts) === 0) { $this->command->error('Error: Could not find instances associated with environment'); } else { $connections = array(); foreach ($hosts as $host) { $connections[] = $this->connectionFactory->createConnection($host, $host, $user, $keyFile); } foreach ($connections as $connection) { $connection->run(array('tail -f ' . $logFile), function ($line) { $this->command->info($line); }); } } }
public function renderCommandField(Command $command) { while (true) { $input = $command->choice($this->getConsoleLabel(), $this->get('choices', []), $this->get('default', null)); $validator = $this->getValidator($input); if ($validator->passes()) { return $input; } else { $command->error($validator->errors()->first()); } } }
/** * Make source file .. * * @param Command $command * @throws SeederException * @return bool|mixed */ public function create(Command $command) { $path = self::getConfig('path'); if (!File::isWritable($path)) { throw new SeederException('Path are not writable. Please chmod!'); } $source = explode(',', self::getSource()); array_walk($source, function ($name) use($path, $command) { $model = 'App\\' . ucfirst(strtolower($name)); if (!isEloquentExists($model)) { $command->error(sprintf('Model %s not exists. Skipped!', $model)); return false; } $fullPath = getFullPathSource($name, $this); if (File::exists($fullPath)) { $command->error(sprintf('Model %s already exists. Skipped!', $name)); return false; } File::put($fullPath, arrayToYaml(['class' => ucfirst($name), 'source' => arrayToYaml(getTableSchema($model), 1)], 1)); $command->info(sprintf('File %s created successfully!', $name)); }); }
public function execWithOutput(string $cmd, Command $console) { // Setup the file descriptors $descriptors = [0 => ['pipe', 'w'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']]; // Start the script $proc = proc_open($cmd, $descriptors, $pipes); // Read the stdin $stdin = stream_get_contents($pipes[0]); fclose($pipes[0]); // Read the stdout $stdout = stream_get_contents($pipes[1]); fclose($pipes[1]); // Read the stderr $stderr = stream_get_contents($pipes[2]); fclose($pipes[2]); // Close the script and get the return code $return_code = proc_close($proc); if ($stdin) { $console->line($stdin); } if ($stdout) { $console->line($stdout); } if ($stderr) { $console->line($stderr); } if (strpos($stdout, 'continue?')) { $console->error('A confirmation has been asked during the shell command execution.'); $console->error('Please manually execute the command "' . $cmd . '" to treat that particular case.'); return exit; } if ($return_code) { $console->error('Error exit code : ' . $return_code); if (!$console->ask('Do you want continue the script execution ? [Y/n]', true)) { return exit; } } }
/** * Clear the settings cache, and backup the databases. * * @param \Illuminate\Console\Command $command * * @return void */ public function fire(Command $command) { $command->line('Clearing settings cache...'); $this->cache->clear(); $command->line('Settings cache cleared!'); $command->line('Backing up database...'); try { $command->call('db:backup', ['--compression' => 'gzip', '--database' => $this->config->get('database.default'), '--destination' => 'local', '--destinationPath' => Carbon::now()->format('Y-m-d H.i.s'), '--no-interaction' => true]); } catch (Exception $e) { $command->error($e->getMessage()); $command->line('Backup skipped!'); } $command->line('Backup completed!'); }
/** * Publish something. */ public function publish() { $sourcePath = $this->getSourcePath(); if (!$this->isDirectory($sourcePath)) { return; } if (!$this->isDirectory($destinationPath = $this->getDestinationPath())) { $this->makeDirectory($destinationPath, 0775, true); } if ($this->copyDirectory($sourcePath, $destinationPath) && $this->showMessage) { $this->console->line("<info>Published</info>: {$this->module->getStudlyName()}"); } else { $this->console->error($this->error); } }
/** * Create validators as specified in the configuration file */ private function createValidators() { $dir = $this->configSettings['pathTo']['validators']; if (!\File::isDirectory($dir)) { \File::makeDirectory($dir); } $pathToValidators = $this->configSettings['pathTo']['templates']; $validator = $this->nameOf('validator'); $fileName = $dir . $validator . '.php'; try { $this->makeFileFromTemplate($fileName, $pathToValidators . 'validator.txt'); } catch (FileNotFoundException $e) { $this->command->error('Template file ' . $pathToValidators . $validator . '.txt does not exist! You need to create it to generate that file!'); } }
/** * Create views as specified in the configuration file */ private function createViews() { $dir = $this->configSettings['pathTo']['views'] . $this->nameOf('viewFolder') . "/"; if (!\File::isDirectory($dir)) { \File::makeDirectory($dir); } $pathToViews = $this->configSettings['pathTo']['templates'] . $this->controllerType . "/"; foreach ($this->configSettings['views'] as $view) { $fileName = $dir . "{$view}.blade.php"; try { $this->makeFileFromTemplate($fileName, $pathToViews . "{$view}.txt"); } catch (FileNotFoundException $e) { $this->command->error("Template file " . $pathToViews . $view . ".txt does not exist! You need to create it to generate that file!"); } } }
/** * Will run the parser, create necessary folders and files * * @param string $name */ protected function createFile($name = null) { if ($name === null) { $name = $this->name; } $file = $this->filename($name); $content = $this->parser->stub($this->stub())->name($name)->setClassNamespace($this->detectNamespace())->setData($this->data)->parse(); if ($this->filesystem->exists($file)) { $this->console->error("The file {$file} already exists."); return; } // Make folders if necessary $this->makeFolders(); // Create the file $this->filesystem->put($file, $content); $this->console->info("Generated {$file}"); }
/** * Generate the module. */ public function generate() { $name = $this->getName(); if (Modules::has($name)) { if ($this->force) { Modules::delete($name); } else { $this->console->error("Module [{$name}] already exist!"); return; } } $this->generateFolders(); $this->generateFiles(); if (!$this->plain) { $this->generateResources(); } $this->console->info("Module [{$name}] created successfully."); }
/** * Publish something. */ public function publish() { if (!$this->console instanceof Command) { $message = "The 'console' property must instance of \\Illuminate\\Console\\Command."; throw new \RuntimeException($message); } if (!$this->getFilesystem()->isDirectory($sourcePath = $this->getSourcePath())) { return; } if (!$this->getFilesystem()->isDirectory($destinationPath = $this->getDestinationPath())) { $this->getFilesystem()->makeDirectory($destinationPath, 0775, true); } if ($this->getFilesystem()->copyDirectory($sourcePath, $destinationPath)) { if ($this->showMessage == true) { $this->console->line("<info>Published</info>: {$this->module->getStudlyName()}"); } } else { $this->console->error($this->error); } }
public function generateLayoutFiles() { $makeLayout = $this->fromFile ? true : $this->command->confirm('Create default layout file [y/n]? (specify css/js files in config) ', true); if ($makeLayout) { $layoutPath = $this->configSettings['pathTo']['layout']; $layoutDir = substr($layoutPath, 0, strrpos($layoutPath, "/")); $next_to_last = strrpos($layoutPath, "/", strrpos($layoutPath, "/") - strlen($layoutPath) - 1) + 1; $layoutName = str_replace("/", ".", substr($layoutPath, $next_to_last, strpos($layoutPath, ".") - $next_to_last)); $directoriesToCreate = array($layoutDir, 'public/js', 'public/css', 'public/img'); foreach ($directoriesToCreate as $dir) { $this->fileCreator->createDirectory($dir); } $content = \File::get($this->configSettings['pathTo']['controllers'] . 'Controller.php'); if (strpos($content, "\$layout") === false) { $content = preg_replace("/Controller {/", "Controller {\n\tprotected \$layout = '{$layoutName}';", $content); \File::put($this->configSettings['pathTo']['controllers'] . 'Controller.php', $content); } $overwrite = false; if (\File::exists($layoutPath)) { $overwrite = $this->command->confirm('Layout file exists. Overwrite? [y/n]? ', true); } if (!\File::exists($layoutPath) || $overwrite) { $this->fileContents = \File::get($this->configSettings['pathTo']['templates'] . 'layout.txt'); $this->fileContents = str_replace("<!--[appName]-->", $this->configSettings['appName'], $this->fileContents); $this->downloadAsset("jquery", "http://code.jquery.com/jquery-1.11.0.min.js"); $this->downloadCSSFramework(); $this->downloadAsset("underscore", "http://underscorejs.org/underscore-min.js"); $this->downloadAsset("handlebars", "http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.3.0.js"); $this->downloadAsset("angular", "https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js"); $this->downloadAsset("ember", "http://builds.emberjs.com/tags/v1.5.0/ember.min.js"); $this->downloadAsset("backbone", "http://backbonejs.org/backbone-min.js"); \File::put($layoutPath, $this->fileContents); } else { $this->command->error('Layout file already exists!'); } } }
/** * Write a string as error output. * * @param string $string * @param null|int|string $verbosity * @return void */ public function error($string, $verbosity = null) { if (zbase_is_console()) { parent::error(' --- ' . $string, $verbosity); } else { var_dump('ERROR: --- ' . $string); } }
/** * Allow the management of tabulation at the beginning of a message * * @param string $message * @param null $verbosity * @param int $tab */ public function error($message, $verbosity = null, $tab = 0) { for ($i = 0; $i < $tab; $i++) { $message = ' ' . $message; } parent::error($message, $verbosity); }