Skip to content

Commit

Permalink
Use constant as default type when adding new keys
Browse files Browse the repository at this point in the history
  • Loading branch information
schlessera committed Dec 12, 2018
1 parent 9a28481 commit 4809462
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
12 changes: 6 additions & 6 deletions features/config-set.feature
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ Feature: Set the value of a constant or variable defined in wp-config.php file
variable_value
"""

When I try `wp config set SOME_NAME some_value`
Then STDERR should be:
When I run `wp config set DEFAULT_TO_CONSTANT some_value`
Then STDOUT should be:
"""
Error: The constant or variable 'SOME_NAME' is not defined in the 'wp-config.php' file. Specify an explicit --type=<type> to add.
Success: Added the constant 'DEFAULT_TO_CONSTANT' to the 'wp-config.php' file with the value 'some_value'.
"""

When I try `wp config get SOME_NAME`
Then STDERR should be:
When I run `wp config get DEFAULT_TO_CONSTANT`
Then STDOUT should be:
"""
Error: The constant or variable 'SOME_NAME' is not defined in the 'wp-config.php' file.
some_value
"""

Scenario: Updating a non-existent value without --add
Expand Down
9 changes: 5 additions & 4 deletions src/Config_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,11 +464,12 @@ public function set( $args, $assoc_args ) {
WP_CLI::error( "Found both a constant and a variable '{$name}' in the 'wp-config.php' file. Use --type=<type> to disambiguate." );
}
if ( ! $has_constant && ! $has_variable ) {
$message = "The constant or variable '{$name}' is not defined in the 'wp-config.php' file.";
if ( $options['add'] ) {
$message .= ' Specify an explicit --type=<type> to add.';
if ( ! $options['add'] ) {
$message = "The constant or variable '{$name}' is not defined in the 'wp-config.php' file.";
WP_CLI::error( $message );
}
WP_CLI::error( $message );
$type = 'constant';
$adding = true;
} else {
$type = $has_constant ? 'constant' : 'variable';
}
Expand Down

0 comments on commit 4809462

Please sign in to comment.