function test_block() { // single line, single tag ob_start(); Cli::block("Output: <info>one, two</info>\n"); $out = ob_get_clean(); $this->assertEquals("Output: [33;33mone, two[0m\n", $out); // multiline, multi tag ob_start(); Cli::block("<success>Yay!</success>\n<error>Oh noes</error>"); $out = ob_get_clean(); $this->assertEquals("[0;32mYay![0m\n[31;31mOh noes[0m", $out); }
<info>./elefant crud-app list-types</info> USAGE; if (!isset($_SERVER['argv'][2])) { Cli::block($usage); die; } $types = array('checkbox', 'date', 'datetime', 'email', 'password', 'pkey', 'radio', 'select', 'text', 'textarea', 'time', 'wysiwyg'); if ($_SERVER['argv'][2] === 'list-types') { Cli::out(' - ' . join("\n - ", $types), 'info'); die; } if (!isset($_SERVER['argv'][3])) { Cli::block($usage); die; } $name = strtolower($_SERVER['argv'][2]); // get plural name $ar = new ActiveResource(); $plural = $ar->pluralize($name); unset($ar); if (file_exists('apps/' . $plural)) { Cli::out('apps/' . $plural . ' already exists. Please choose a different name for your new app.', 'info'); die; } // build list of fields $fields = array(); $pkey = false; for ($i = 3; $i < count($_SERVER['argv']); $i++) {
<info>helper-docs <helper></info> Show documentation for a helper <info>generate-key</info> Generate a random 32 character key <info>generate-password <length(8)></info> Generate a random password <info>encrypt-password <password></info> Encrypt a password for the db <info>bundle-translations <appname></info> Bundle translations into an app <info>version</info> Output the Elefant version number <info>help</info> Print this help output HELP; // Extend command list with those from apps/*/conf/cli.php $files = glob('apps/*/conf/cli.php'); if ($files) { $commands = array(); foreach ($files as $file) { $parsed = parse_ini_file($file); if (!$parsed || !isset($parsed['commands'])) { continue; } $commands = array_merge($commands, $parsed['commands']); } if (count($commands) > 0) { $help .= "Extended commands:\n\n"; foreach ($commands as $cmd => $desc) { $help .= sprintf(" <info>%-37s</info> %s\n", $cmd, $desc); } $help .= "\n"; } } Cli::block($help);
if (trim($sql) === 'begin' || trim($sql) === 'commit') { continue; } if (!DB::execute($sql)) { Cli::out('** Error: ' . DB::error(), 'error'); DB::rollback(); return; } } // change the admin user's password $pass = generate_password(8); $date = gmdate('Y-m-d H:i:s'); if (!DB::execute("update `#prefix#user` set `email` = ?, `password` = ? where `id` = 1", $conf['General']['email_from'], User::encrypt_pass($pass))) { Cli::out('Error: ' . DB::error(), 'error'); DB::rollback(); return; } DB::commit(); // respond with the root password echo "Database created. Your initial admin account is:\n"; Cli::block('Username: <info>' . $conf['General']['email_from'] . "</info>\n"); Cli::block('Password: <info>' . $pass . "</info>\n"); // create versions entries for initial content $wp = new Webpage('index'); Versions::add($wp); $b = new Block('members'); Versions::add($b); // disable the installer @umask(00); @touch('conf/installed'); echo "Done.\n";