Skip to content

Commit 21daa36

Browse files
authored
Merge pull request #80 from wp-cli/47-default-type-to-constant
Use constant as default type when adding new keys
2 parents 9eded8f + 4809462 commit 21daa36

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

features/config-set.feature

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ Feature: Set the value of a constant or variable defined in wp-config.php file
4141
variable_value
4242
"""
4343

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

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

5656
Scenario: Updating a non-existent value without --add

src/Config_Command.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,11 +474,12 @@ public function set( $args, $assoc_args ) {
474474
WP_CLI::error( "Found both a constant and a variable '{$name}' in the 'wp-config.php' file. Use --type=<type> to disambiguate." );
475475
}
476476
if ( ! $has_constant && ! $has_variable ) {
477-
$message = "The constant or variable '{$name}' is not defined in the 'wp-config.php' file.";
478-
if ( $options['add'] ) {
479-
$message .= ' Specify an explicit --type=<type> to add.';
477+
if ( ! $options['add'] ) {
478+
$message = "The constant or variable '{$name}' is not defined in the 'wp-config.php' file.";
479+
WP_CLI::error( $message );
480480
}
481-
WP_CLI::error( $message );
481+
$type = 'constant';
482+
$adding = true;
482483
} else {
483484
$type = $has_constant ? 'constant' : 'variable';
484485
}

0 commit comments

Comments
 (0)