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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
"theme path",
"theme search",
"theme status",
"theme update"
"theme update",
"theme mod list"
]
}
}
51 changes: 51 additions & 0 deletions features/theme-mod-list.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Feature: Manage WordPress theme mods list
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests should be written with a list of theme mods that actually contain values, otherwise the tests could just succeed by random chance.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use something like this to pre-populate the list:

Background:
  Given a WP install
  And I run `wp theme mod set key_a value_a`
  And I run `wp theme mod set key_b value_b`

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schlessera Done. can you please check again? 😃


Background:
Given a WP install
And I run `wp theme mod set key_a value_a`
And I run `wp theme mod set key_b value_b`

Scenario: Getting theme mods
When I run `wp theme mod list`
Then STDOUT should be a table containing rows:
| key | value |

When I run `wp theme mod list --field=key`
Then STDOUT should be:
"""
key_a
key_b
"""

When I run `wp theme mod list --field=value`
Then STDOUT should be:
"""
value_a
value_b
"""

When I run `wp theme mod list --format=json`
Then STDOUT should be:
"""
[{"key":"key_a","value":"value_a"},{"key":"key_b","value":"value_b"}]
"""

When I run `wp theme mod list --format=csv`
Then STDOUT should be:
"""
key,value
key_a,value_a
key_b,value_b
"""

When I run `wp theme mod list --format=yaml`
Then STDOUT should be:
"""
---
-
key: key_a
value: value_a
-
key: key_b
value: value_b
"""
40 changes: 40 additions & 0 deletions src/Theme_Mod_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,46 @@ public function get( $args = array(), $assoc_args = array() ) {

}

/**
* Gets a list of theme mods.
*
* ## OPTIONS
*
* [--field=<field>]
* : Returns the value of a single field.
*
* [--format=<format>]
* : Render output in a particular format.
* ---
* default: table
* options:
* - table
* - json
* - csv
* - yaml
* ---
*
* ## EXAMPLES
*
* # Gets a list of theme mods.
* $ wp theme mod list
* +------------------+---------+
* | key | value |
* +------------------+---------+
* | background_color | dd3333 |
* | link_color | #dd9933 |
* | main_text_color | #8224e3 |
* +------------------+---------+
*
* @subcommand list
*/
public function list_( $args = array(), $assoc_args = array() ) {

$assoc_args['all'] = 1;

$this->get( $args, $assoc_args );
}

/**
* Removes one or more theme mods.
*
Expand Down