Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Example usage:
wp home [help] ...
wp option [add|update|delete|get|help] ...
wp plugin [status|activate|deactivate|install|delete|update|help] ...
wp theme [list|details|activate|help] ...
wp theme [status|details|activate|help] ...
```

So this tells us which commands are installed: eg. google-sitemap, core, home, ...
Expand Down Expand Up @@ -126,4 +126,4 @@ Commands to be written:
Requirements
------------

* PHP >= 5.3
* PHP >= 5.3
93 changes: 63 additions & 30 deletions class-wp-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,76 +13,76 @@ class WP_CLI {
* Add a command to the wp-cli list of commands
*
* @param string $name The name of the command that will be used in the cli
* @param string $class The class to manage the command
* @param string $class The class to manage the command
* @return void
* @author Andreas Creten
*/
public function addCommand($name, $class) {
self::$commands[$name] = $class;
}

/**
* Display a message in the cli
*
* @param string $message
* @param string $message
* @return void
* @author Andreas Creten
*/
static function out($message) {
\cli\out($message);
}

/**
* Display a message in the CLI and end with a newline
*
* @param string $message
* @param string $message
* @return void
* @author Andreas Creten
*/
static function line($message = '') {
\cli\line($message);
}

/**
* Display an error in the CLI and end with a newline
*
* @param string $message
* @param string $label
* @param string $message
* @param string $label
* @return void
* @author Andreas Creten
*/
static function error($message, $label = 'Error') {
\cli\line('%R'.$label.': %n'.self::errorToString($message));
}

/**
* Display a success in the CLI and end with a newline
*
* @param string $message
* @param string $label
* @param string $message
* @param string $label
* @return void
* @author Andreas Creten
*/
static function success($message, $label = 'Success') {
\cli\line('%G'.$label.': %n'.$message);
}

/**
* Display a warning in the CLI and end with a newline
*
* @param string $message
* @param string $label
* @param string $message
* @param string $label
* @return void
* @author Andreas Creten
*/
static function warning($message, $label = 'Warning') {
\cli\line('%C'.$label.': %n'.$message);
}

/**
* Convert a wp_error into a String
*
* @param mixed $errors
* @param mixed $errors
* @return string
* @author Andreas Creten
*/
Expand All @@ -99,7 +99,7 @@ static function errorToString($errors) {
}
}
}

/**
* Display the help function for the wp-cli
*
Expand All @@ -117,6 +117,39 @@ static function generalHelp() {
self::line(' ...');
}
}

/**
* Display a legend
*
* @param array( code => title ) $legend
* @return void
*/
static function legend($legend) {
$legend['%yU'] = 'Update Available';

$legend_line = array();
foreach ( $legend as $key => $title )
$legend_line[] = "$key = $title%n";

WP_CLI::line( 'Legend: ' . implode( ', ', $legend_line ) );
}

/**
* Return the beginning of the status line for a certain plugin or theme
*
* @param string $item The plugin or theme name
* @param string $key The transient key
*
* @return string
*/
static function get_update_status( $item, $key ) {
$update_list = get_site_transient( $key );

if ( isset( $update_list->response[ $item ] ) )
return ' %yU%n';

return ' ';
}
}

/**
Expand All @@ -134,58 +167,58 @@ function __construct($args = array()) {
$defaults = array('url' => '', 'nonce' => '', 'title' => '', 'context' => false);
$this->options = wp_parse_args($args, $defaults);
}

function set_upgrader(&$upgrader) {
if(is_object($upgrader)) {
$this->upgrader =& $upgrader;
}

$this->add_strings();
}

function add_strings() {}

function set_result($result) {
$this->result = $result;
}

function request_filesystem_credentials($error = false) {
$url = $this->options['url'];
$context = $this->options['context'];
if(!empty($this->options['nonce'])) {
$url = wp_nonce_url($url, $this->options['nonce']);
}

// Possible to bring inline, Leaving as is for now.
return request_filesystem_credentials($url, '', $error, $context);
}

function header() {}
function footer() {}

function error($errors) {
$this->feedback(WP_CLI::errorToString($errors));
}

function feedback($string) {
if(isset( $this->upgrader->strings[$string]))
$string = $this->upgrader->strings[$string];

if(strpos($string, '%') !== false) {
$args = func_get_args();
$args = array_splice($args, 1);
if(!empty($args)) {
$string = vsprintf($string, $args);
}

}
if(empty($string)) {
return;
}

echo $string;
}

function before() {}
function after() {}
}
}
Loading