/**
* Update an option.
*
* ## OPTIONS
*
* <key>
* : The name of the option to add.
*
* [<value>]
* : The new value. If ommited, the value is read from STDIN.
*
* [--format=<format>]
* : The serialization format for the value. Default is plaintext.
*
* ## EXAMPLES
*
* # Update an option by reading from a file
* wp option update my_option < value.txt
*
* # Update one option on multiple sites using xargs
* wp site list --field=url | xargs -n1 -I {} sh -c 'wp --url={} option update <key> <value>'
*
* @alias set
*/
public function update($args, $assoc_args)
{
$key = $args[0];
$value = WP_CLI::get_value_from_arg_or_stdin($args, 1);
$value = WP_CLI::read_value($value, $assoc_args);
$result = update_option($key, $value);
// update_option() returns false if the value is the same
if (!$result && $value != get_option($key)) {
WP_CLI::error("Could not update option '{$key}'.");
} else {
WP_CLI::success("Updated '{$key}' option.");
}
}