Unverified Commit 605ba582 authored by Peter J. Herrel's avatar Peter J. Herrel
Browse files

make 'wp pll option get' less verbose, i.e. usable

parent 6cbf11b1
......@@ -618,8 +618,8 @@ wp pll option default [<language-code>]
**EXAMPLES**
wp pll option default
wp pll option default nl
$ wp pll option default
$ wp pll option default nl
......@@ -628,7 +628,7 @@ wp pll option default [<language-code>]
Get Polylang settings.
~~~
wp pll option get <option_name>
wp pll option get <option_name> [--format=<format>]
~~~
**OPTIONS**
......@@ -636,9 +636,19 @@ wp pll option get <option_name>
<option_name>
Option name. Use the options subcommand to get a list of accepted values. Required.
[--format=<format>]
Get value in a particular format.
---
default: var_export
options:
- var_export
- json
- yaml
---
**EXAMPLES**
wp pll option get default_lang
$ wp pll option get default_lang
......@@ -672,7 +682,7 @@ wp pll option reset
**EXAMPLES**
wp pll option reset
$ wp pll option reset
......@@ -762,7 +772,7 @@ wp pll option update <option_name> <new_value>
**EXAMPLES**
wp pll option update default_lang nl
$ wp pll option update default_lang nl
......
......@@ -11,7 +11,7 @@ Feature: Manage Polylang settings
Scenario: Get the default language code (slug)
When I run `wp pll option get default_lang`
Then STDOUT should contain:
Then STDOUT should be:
"""
Success: The value of default_lang is nl
nl
"""
......@@ -175,6 +175,17 @@ class Cli {
\WP_CLI::log( $message );
}
/**
* Display a value, in various formats
*
* @param mixed $value Value to display.
* @param array $assoc_args Arguments passed to the command, determining format.
*/
public function print_value( $value, $assoc_args ) {
\WP_CLI::print_value( $value, $assoc_args );
}
}
}
......@@ -63,7 +63,7 @@ class OptionCommand extends BaseCommand
*
* ## EXAMPLES
*
* wp pll option reset
* $ wp pll option reset
*/
public function reset( $args, $assoc_args ) {
......@@ -99,9 +99,19 @@ class OptionCommand extends BaseCommand
* <option_name>
* : Option name. Use the options subcommand to get a list of accepted values. Required.
*
* [--format=<format>]
* : Get value in a particular format.
* ---
* default: var_export
* options:
* - var_export
* - json
* - yaml
* ---
*
* ## EXAMPLES
*
* wp pll option get default_lang
* $ wp pll option get default_lang
*/
public function get( $args, $assoc_args ) {
......@@ -118,7 +128,7 @@ class OptionCommand extends BaseCommand
$this->cli->error( sprintf( 'Invalid option name: %s', $args[0] ) );
}
$this->cli->success( sprintf( 'The value of %s is %s', $args[0], maybe_serialize( $option[$args[0]] ) ) );
$this->cli->print_value( $option[$args[0]], $assoc_args );
}
/**
......@@ -134,7 +144,7 @@ class OptionCommand extends BaseCommand
*
* ## EXAMPLES
*
* wp pll option update default_lang nl
* $ wp pll option update default_lang nl
*/
public function update( $args, $assoc_args ) {
......@@ -181,8 +191,8 @@ class OptionCommand extends BaseCommand
*
* ## EXAMPLES
*
* wp pll option default
* wp pll option default nl
* $ wp pll option default
* $ wp pll option default nl
*
* @synopsis [<language-code>]
*
......@@ -194,14 +204,14 @@ class OptionCommand extends BaseCommand
return $this->cli->warning( "No languages are currently configured." );
}
# get the default language
$default = $this->api->default_language();
# if no language provided, return the default language
if ( empty( $args ) ) {
return $this->cli->success( "{$default} is currently the default language" );
return $this->get( array( 'default_lang' ), array() );
}
# get the default language
$default = $this->api->default_language();
# sanitize user input
$language = isset( $args[0] ) && $args[0] ? sanitize_title_with_dashes( $args[0] ) : false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment