Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Commit 2c94a1f

Browse files
authored
Merge pull request #3 from creode/feature/add-force-option-to-install-command
Added a —force option to the install command.
2 parents 670ae2f + 055d107 commit 2c94a1f

4 files changed

Lines changed: 20 additions & 9 deletions

File tree

includes/class-command-base.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ abstract protected function name(): string;
3434
/**
3535
* This class must be invocable.
3636
*
37-
* @param array $args An array of arguments might be provided.
37+
* @param array $args Optional. Command arguments.
38+
* @param array $assoc_args Optional. Associative array of command options.
3839
*/
39-
abstract public function __invoke( array $args = array() );
40+
abstract public function __invoke( array $args = array(), array $assoc_args = array() );
4041

4142
/**
4243
* Registers this command.

includes/class-installer.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,25 @@ private function update_file_string_replacements() {
9090

9191
/**
9292
* Installs theme files.
93+
*
94+
* @param bool $force (Optional) Whether theme files will be overidden. If omitted, theme files will only be created if they do not exist. Defaults to false if not specified.
9395
*/
94-
public function install() {
95-
$this->copy_theme_files();
96+
public function install( bool $force = false ) {
97+
$this->copy_theme_files( $force );
9698
new All_Blocks_Scss_File_Generator( $this->theme_name, $this->message_handler );
9799
new Asset_Builder( $this->theme_name, $this->message_handler );
98100
}
99101

100102
/**
101103
* Copies theme files from the theme-template directory into the specified location.
104+
*
105+
* @param bool $force (Optional) Whether theme files will be overidden. If omitted, theme files will only be created if they do not exist. Defaults to false if not specified.
102106
*/
103-
private function copy_theme_files() {
107+
private function copy_theme_files( bool $force = false ) {
104108
Helpers::copy_directory(
105109
__DIR__ . '/../theme-template',
106110
get_theme_root() . '/' . $this->theme_name,
107-
true,
111+
! $force,
108112
function ( string $source_file_path, $destination_file_path ) {
109113
$this->file_string_replacer->replace( $destination_file_path );
110114
}

includes/commands/class-build-command.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ protected function name(): string {
3636
* $ wp creode-theme:build
3737
*
3838
* @param array $args Not used.
39+
* @param array $assoc_args Not used.
3940
*/
40-
public function __invoke( array $args = array() ) {
41+
public function __invoke( array $args = array(), array $assoc_args = array() ) {
4142
$message_handler = new Command_Message_Handler();
4243

4344
try {

includes/commands/class-install-theme-command.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ protected function name(): string {
3636
* [<theme-directory>]
3737
* : The directory name of the theme to install files to.
3838
* If omitted, the active theme will be used.
39+
* [--force]
40+
* : Whether theme files will be overidden.
41+
* If omitted, theme files will only be created if they do not exist.
42+
* Defaults to false if not specified.
3943
*
4044
* ## EXAMPLES
4145
*
@@ -46,13 +50,14 @@ protected function name(): string {
4650
* $ wp creode-theme:install my-child-theme
4751
*
4852
* @param array $args Optional. Command arguments. [<theme-directory>].
53+
* @param array $assoc_args Optional. Associative array of command options. ['force' => bool].
4954
*/
50-
public function __invoke( array $args = array() ) {
55+
public function __invoke( array $args = array(), array $assoc_args = array() ) {
5156
$theme_name = isset( $args[0] ) ? $args[0] : null;
5257

5358
try {
5459
$installer = new Installer( $theme_name, new Command_Message_Handler() );
55-
$installer->install();
60+
$installer->install( ! empty( $assoc_args['force'] ) );
5661
} catch ( Exception $e ) {
5762
WP_CLI::error( $e->getMessage() );
5863
}

0 commit comments

Comments
 (0)