Skip to content

Commit

Permalink
Warn if no plugin or theme has been specified
Browse files Browse the repository at this point in the history
See #27.
  • Loading branch information
swissspidy committed Aug 2, 2018
1 parent d798f10 commit 00d139c
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
19 changes: 19 additions & 0 deletions features/language-plugin.feature
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,22 @@ Feature: Manage translation files for a WordPress install
"""
And STDOUT should be empty
And the return code should be 0

@require-wp-4.0
Scenario: Not providing plugin slugs should throw an error unless --all given
Given a WP install

When I try `wp language plugin list`
Then the return code should be 1
And STDERR should be:
"""
Error: Please specify one or more plugins, or use --all.
"""
And STDOUT should be empty

Given I run `wp plugin uninstall --all`
When I run `wp language plugin list --all`
Then STDOUT should be:
"""
Success: No plugins installed.
"""
21 changes: 21 additions & 0 deletions features/language-theme.feature
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,24 @@ Feature: Manage translation files for a WordPress install
"""
And STDOUT should be empty
And the return code should be 0

@require-wp-4.0
Scenario: Not providing theme slugs should throw an error unless --all given
Given a WP install
And I run `wp theme path`
And save STDOUT as {THEME_DIR}

When I try `wp language theme list`
Then the return code should be 1
And STDERR should be:
"""
Error: Please specify one or more themes, or use --all.
"""
And STDOUT should be empty

Given an empty {THEME_DIR} directory
When I run `wp language theme list --all`
Then STDOUT should be:
"""
Success: No theme installed.
"""
11 changes: 10 additions & 1 deletion src/Plugin_Language_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Plugin_Language_Command extends WP_CLI\CommandWithTranslation {
);

/**
* Lists all available languages.
* Lists all available languages for one or more plugins.
*
* ## OPTIONS
*
Expand Down Expand Up @@ -97,10 +97,19 @@ class Plugin_Language_Command extends WP_CLI\CommandWithTranslation {
public function list_( $args, $assoc_args ) {
$all = \WP_CLI\Utils\get_flag_value( $assoc_args, 'all', false );

if ( ! $all && empty( $args ) ) {
WP_CLI::error( 'Please specify one or more plugins, or use --all.' );
}

if ( $all ) {
$args = array_map( function( $file ){
return \WP_CLI\Utils\get_plugin_name( $file );
}, array_keys( $this->get_all_plugins() ) );

if ( empty( $args ) ) {
WP_CLI::success( 'No plugins installed.' );
return;
}
}

$updates = $this->get_translation_updates();
Expand Down
11 changes: 10 additions & 1 deletion src/Theme_Language_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Theme_Language_Command extends WP_CLI\CommandWithTranslation {
);

/**
* Lists all available languages.
* Lists all available languages for one or more themes.
*
* ## OPTIONS
*
Expand Down Expand Up @@ -97,10 +97,19 @@ class Theme_Language_Command extends WP_CLI\CommandWithTranslation {
public function list_( $args, $assoc_args ) {
$all = \WP_CLI\Utils\get_flag_value( $assoc_args, 'all', false );

if ( ! $all && empty( $args ) ) {
WP_CLI::error( 'Please specify one or more themes, or use --all.' );
}

if ( $all ) {
$args = array_map( function( $file ){
return \WP_CLI\Utils\get_theme_name( $file );
}, array_keys( wp_get_themes() ) );

if ( empty( $args ) ) {
WP_CLI::success( 'No themes installed.' );
return;
}
}

$updates = $this->get_translation_updates();
Expand Down

0 comments on commit 00d139c

Please sign in to comment.