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
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"commands": [
"config",
"config set",
"config get"
"config get",
"config unset",
"config list"
]
}
}
84 changes: 84 additions & 0 deletions src/Config_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,88 @@ public function set( $args, $assoc_args ) {

$this->fs->dumpFile( $config_file_path, Spyc::YAMLDump( $config, false, false, true ) );
}

/**
* Unset a config value
*
* ## OPTIONS
*
* <key>
* : Key of config to unset
*
* ## EXAMPLES
*
* # Remove value from config
* $ ee config unset cloudflare-api-key
*
*/
public function unset( $args, $assoc_args ) {
$config_file_path = getenv( 'EE_CONFIG_PATH' ) ? getenv( 'EE_CONFIG_PATH' ) : EE_ROOT_DIR . '/config/config.yml';
$config = Spyc::YAMLLoad( $config_file_path );
$key = $args[0];

if ( ! isset( $config[ $key ] ) ) {
EE::error( "No config value with key '$key' set" );
}

unset( $config[ $key ] );

$this->fs->dumpFile( $config_file_path, Spyc::YAMLDump( $config, false, false, true ) );
}

/**
* Lists the config values.
*
* [--format=<format>]
* : Render output in a particular format.
* ---
* default: table
* options:
* - table
* - csv
* - yaml
* - json
* - count
* - text
* ---
*
* ## EXAMPLES
*
* # List all config values
* $ ee config list
*
* # List all config values in JSON
* $ ee config list --format=json
*
* @subcommand list
*/
public function _list( $args, $assoc_args ) {
$config_file_path = getenv( 'EE_CONFIG_PATH' ) ? getenv( 'EE_CONFIG_PATH' ) : EE_ROOT_DIR . '/config/config.yml';
$config = Spyc::YAMLLoad( $config_file_path );
$format = \EE\Utils\get_flag_value( $assoc_args, 'format' );

if ( empty( $config ) ) {
\EE::error( 'No config values found!' );
}

if ( 'text' === $format ) {
foreach ( $config as $key => $value ) {
\EE::log( $key . ': ' . $value );
}
} else {
$result = array_map(
function ( $key, $value ) {
return [
'key' => $key,
'value' => $value,
];
},
array_keys( $config ),
$config
);

$formatter = new \EE\Formatter( $assoc_args, [ 'key', 'value' ] );
$formatter->display_items( $result );
}
}
}