/** * Display a message in the cli * * @param string $message */ static function out($message) { if (WP_CLI_QUIET) { return; } \cli\out($message); }
function logger_r($foo) { global $verbose; if ($verbose == 0) { return; } \cli\out(print_r($foo)); }
/** * Call api contact.delete for contact ID * * @param int $cont_id */ function markContactDeleted($cont_id) { $apiResult = cvCli('contact', 'delete', array('id' => $cont_id)); if ($apiResult->is_error) { cli\out(var_export($apiResult, TRUE)); } else { cli\line("Contact ID#{$cont_id} moved to Trash."); } }
/** * Create a "Job" Tag based on a date and script verb. * * @param type $date_str * @param type $job_action * @return type */ function createJobTag($date_str, $job_action) { $apiResult = cvCli('tag', 'create', array('name' => "{$date_str} {$job_action}", 'description' => "Bulk Script {$job_action} Contacts {$date_str}")); $values = get_object_vars($apiResult->values); foreach ($values as $tag) { cli\out("Created tag: {$tag->name} \n"); } return $apiResult; }
/** * Prints the progress bar to the screen with percent complete, elapsed time * and estimated total time. * * @param boolean $finish `true` if this was called from * `cli\Notify::finish()`, `false` otherwise. * @see cli\out() * @see cli\Notify::formatTime() * @see cli\Notify::elapsed() * @see cli\Progress::estimated(); * @see cli\Progress::percent() * @see cli\Shell::columns() */ public function display($finish = false) { $_percent = $this->percent(); $percent = str_pad(floor($_percent * 100), 3); $msg = $this->_message; $msg = \cli\render($this->_formatMessage, compact('msg', 'percent')); $estimated = $this->formatTime($this->estimated()); $elapsed = str_pad($this->formatTime($this->elapsed()), strlen($estimated)); $timing = \cli\render($this->_formatTiming, compact('elapsed', 'estimated')); $size = \cli\Shell::columns(); $size -= strlen($msg . $timing); $bar = str_repeat($this->_bars[0], floor($_percent * $size)) . $this->_bars[1]; // substr is needed to trim off the bar cap at 100% $bar = substr(str_pad($bar, $size, ' '), 0, $size); \cli\out($this->_format, compact('msg', 'bar', 'timing')); }
/** * @param array $servers */ private function listServers($servers) { $default = ''; if (isset($servers['__default'])) { $default = $servers['__default']; unset($servers['__default']); } $table = new \cli\Table(); $table->setHeaders(array('Name', 'Host', 'Auth mechanism')); foreach ($servers as $name => $data) { if ($default == $name) { $name .= ' (default)'; } $table->addRow(array($name, $data['address'], current(explode(' ', $data['auth'])))); } $table->display(); \cli\out($default); }
usleep($sleep); } } $notify->finish(); } while (true) { $choice = \cli\menu($menu, null, 'Choose an example'); \cli\line(); switch ($choice) { case 'quit': break 2; case 'out_out': \cli\out(" \\cli\\out sends output to STDOUT\n"); \cli\out(" It does not automatically append a new line\n"); \cli\out(" It does accept any number of %s which are then %s to %s for formatting\n", 'arguments', 'passed', 'sprintf'); \cli\out(" Alternatively, {:a} can use an {:b} as the second argument.\n", array('a' => 'you', 'b' => 'array')); break; case 'out_err': \cli\err(' \\cli\\err sends output to STDERR'); \cli\err(' It does automatically append a new line'); \cli\err(' It does accept any number of %s which are then %s to %s for formatting', 'arguments', 'passed', 'sprintf'); \cli\err(' Alternatively, {:a} can use an {:b} as the second argument.', array('a' => 'you', 'b' => 'array')); break; case 'out_line': \cli\line(' \\cli\\line forwards to \\cli\\out for output'); \cli\line(' It does automatically append a new line'); \cli\line(' It does accept any number of %s which are then %s to %s for formatting', 'arguments', 'passed', 'sprintf'); \cli\line(' Alternatively, {:a} can use an {:b} as the second argument.', array('a' => 'you', 'b' => 'array')); break; case 'notify_dots': test_notify(new \cli\notify\Dots(' \\cli\\notify\\Dots cycles through a set number of dots'));
/** * Display a message in the cli * * @param string $message */ public static function out($message) { if (ETSIS_CLI_QUIET) { return; } \cli\out($message); }
/** * waits for input from the user (terminated by a carriage-return / newline) * * @param string $prompt text to prompt on the console * * @return string the text inputted on the command line */ protected function getInput($prompt = '>') { \cli\out('%s: ', $prompt); $handle = fopen("php://stdin", "r"); $line = fgets($handle); fclose($handle); return trim($line); }
public function testTables() { $this->resetStreams(); $suffix = \cli\Shell::isPiped() ? "_piped" : ""; $this->assertTrue(is_numeric($columns = \cli\Shell::columns())); $headers = array('First Name', 'Last Name', 'City', 'State'); $data = array(array('Maryam', 'Elliott', 'Elizabeth City', 'SD'), array('Jerry', 'Washington', 'Bessemer', 'ME'), array('Allegra', 'Hopkins', 'Altoona', 'ME'), array('Audrey', 'Oneil', 'Dalton', 'SK')); $table = new \cli\Table(); $table->setRenderer(new \cli\table\Ascii()); $table->setHeaders($headers); $table->setRows($data); $table->display(); $output = $this->getStreams(); $this->assertEquals("", $output['errors']); $this->assertEquals(file_get_contents("test/output/table_1"), $output['contents']); $this->resetStreams(); $table->sort(1); $table->display(); $output = $this->getStreams(); $this->assertEquals("", $output['errors']); $this->assertEquals(file_get_contents("test/output/table_2"), $output['contents']); $this->resetStreams(); foreach ($data as $k => $v) { $data[$k] = array_combine(array("name", "surname", "city", "state"), $v); } $renderer = new \cli\table\Ascii(); $renderer->setCharacters(array("corner" => "x", "line" => "=", "border" => "!")); $table = new \cli\Table($data); $table->setRenderer($renderer); $table->sort("surname"); $table->display(); $output = $this->getStreams(); $this->assertEquals("", $output['errors']); $this->assertEquals(file_get_contents("test/output/table_3"), $output['contents']); $this->assertEquals("[0m", \cli\Colors::color("reset")); $this->assertEquals("foo\tbar", \cli\table\Tabular::row(array("foo", "bar"))); $this->assertNull(\cli\table\Tabular::border()); // test output $this->resetStreams(); \cli\out(" \\cli\\out sends output to STDOUT\n"); \cli\out(" It does not automatically append a new line\n"); \cli\out(" It does accept any number of %s which are then %s to %s for formatting\n", 'arguments', 'passed', 'sprintf'); \cli\out(" Alternatively, {:a} can use an {:b} as the second argument.\n\n", array('a' => 'you', 'b' => 'array')); \cli\err(' \\cli\\err sends output to STDERR'); \cli\err(' It does automatically append a new line'); \cli\err(' It does accept any number of %s which are then %s to %s for formatting', 'arguments', 'passed', 'sprintf'); \cli\err(" Alternatively, {:a} can use an {:b} as the second argument.\n", array('a' => 'you', 'b' => 'array')); \cli\line(' \\cli\\line forwards to \\cli\\out for output'); \cli\line(' It does automatically append a new line'); \cli\line(' It does accept any number of %s which are then %s to %s for formatting', 'arguments', 'passed', 'sprintf'); \cli\line(" Alternatively, {:a} can use an {:b} as the second argument.\n", array('a' => 'you', 'b' => 'array')); $output = $this->getStreams(); $this->assertEquals(file_get_contents("test/output/out_errors"), $output['errors']); $this->assertEquals(file_get_contents("test/output/out_contents"), $output['contents']); $string = ""; $string .= \cli\render(' \\cli\\err sends output to STDERR' . "\n"); $string .= \cli\render(' It does automatically append a new line' . "\n"); $string .= \cli\render(' It does accept any number of %s which are then %s to %s for formatting' . "\n", 'arguments', 'passed', 'sprintf'); $string .= \cli\render(" Alternatively, {:a} can use an {:b} as the second argument.\n\n", array('a' => 'you', 'b' => 'array')); $this->assertEquals(file_get_contents("test/output/out_errors"), $string); $this->resetStreams(); $in = tmpfile(); fputs($in, "quit\n"); fseek($in, 0); \cli\Streams::setStream("in", $in); $line = \cli\prompt("prompt", false, "# "); $output = $this->getStreams(); $this->assertEquals("quit", $line); $this->assertEquals("", $output['errors']); $this->assertEquals("prompt# ", $output['contents']); fseek($in, 0); $this->assertEquals("quit", \cli\input()); fclose($in); }
/** * Shows help dialog. * * @author Benjamin Carl <*****@*****.**> * @return void * @access protected * @static */ protected static function showHelp() { \cli\line(); \cli\out(self::$arguments->getHelpScreen(\cli\Colors::colorize('%N%n%gAvailable commands:'))); \cli\line(); }
/** * Displays an input prompt. If no default value is provided the prompt will * continue displaying until input is received. * * @param string $question The question to ask the user. * @param string $default A default value if the user provides no input. * @param string $marker A string to append to the question and default value * on display. * @return string The users input. * @see cli\input() */ function prompt($question, $default = false, $marker = ': ') { if ($default && strpos($question, '[') === false) { $question .= ' [' . $default . ']'; } while (true) { \cli\out($question . $marker); $line = input(); if (!empty($line)) { return $line; } if ($default !== false) { return $default; } } }
/** * Display a message in the cli * * @param string $message */ static function out($message) { \cli\out($message); }
/** * This method is the meat of all Notifiers. First we increment the ticker * and then update the display if enough time has passed since our last tick. * * @param int $increment The amount to increment by. * @see cli\Notify::increment() * @see cli\Notify::shouldUpdate() * @see cli\Notify::display() */ public function tick($increment = 1) { $this->increment($increment); if ($this->shouldUpdate()) { \cli\out("\r"); $this->display(); } }
function printLossDot() { cli\out('%n%0.'); }