From 055d107ca0e1268f281f32e4a49e9d5eedf62354 Mon Sep 17 00:00:00 2001 From: Ben Leonard Date: Wed, 13 Aug 2025 12:46:48 +0100 Subject: [PATCH] =?UTF-8?q?Added=20a=20=E2=80=94force=20option=20to=20the?= =?UTF-8?q?=20install=20command.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/class-command-base.php | 5 +++-- includes/class-installer.php | 12 ++++++++---- includes/commands/class-build-command.php | 3 ++- includes/commands/class-install-theme-command.php | 9 +++++++-- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/includes/class-command-base.php b/includes/class-command-base.php index fce37d3..f2ab831 100644 --- a/includes/class-command-base.php +++ b/includes/class-command-base.php @@ -34,9 +34,10 @@ abstract protected function name(): string; /** * This class must be invocable. * - * @param array $args An array of arguments might be provided. + * @param array $args Optional. Command arguments. + * @param array $assoc_args Optional. Associative array of command options. */ - abstract public function __invoke( array $args = array() ); + abstract public function __invoke( array $args = array(), array $assoc_args = array() ); /** * Registers this command. diff --git a/includes/class-installer.php b/includes/class-installer.php index ff09c4d..831b112 100644 --- a/includes/class-installer.php +++ b/includes/class-installer.php @@ -90,21 +90,25 @@ private function update_file_string_replacements() { /** * Installs theme files. + * + * @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. */ - public function install() { - $this->copy_theme_files(); + public function install( bool $force = false ) { + $this->copy_theme_files( $force ); new All_Blocks_Scss_File_Generator( $this->theme_name, $this->message_handler ); new Asset_Builder( $this->theme_name, $this->message_handler ); } /** * Copies theme files from the theme-template directory into the specified location. + * + * @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. */ - private function copy_theme_files() { + private function copy_theme_files( bool $force = false ) { Helpers::copy_directory( __DIR__ . '/../theme-template', get_theme_root() . '/' . $this->theme_name, - true, + ! $force, function ( string $source_file_path, $destination_file_path ) { $this->file_string_replacer->replace( $destination_file_path ); } diff --git a/includes/commands/class-build-command.php b/includes/commands/class-build-command.php index 7b9bb22..1b6251e 100644 --- a/includes/commands/class-build-command.php +++ b/includes/commands/class-build-command.php @@ -36,8 +36,9 @@ protected function name(): string { * $ wp creode-theme:build * * @param array $args Not used. + * @param array $assoc_args Not used. */ - public function __invoke( array $args = array() ) { + public function __invoke( array $args = array(), array $assoc_args = array() ) { $message_handler = new Command_Message_Handler(); try { diff --git a/includes/commands/class-install-theme-command.php b/includes/commands/class-install-theme-command.php index 6f664b2..e10b393 100644 --- a/includes/commands/class-install-theme-command.php +++ b/includes/commands/class-install-theme-command.php @@ -36,6 +36,10 @@ protected function name(): string { * [] * : The directory name of the theme to install files to. * If omitted, the active theme will be used. + * [--force] + * : 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. * * ## EXAMPLES * @@ -46,13 +50,14 @@ protected function name(): string { * $ wp creode-theme:install my-child-theme * * @param array $args Optional. Command arguments. []. + * @param array $assoc_args Optional. Associative array of command options. ['force' => bool]. */ - public function __invoke( array $args = array() ) { + public function __invoke( array $args = array(), array $assoc_args = array() ) { $theme_name = isset( $args[0] ) ? $args[0] : null; try { $installer = new Installer( $theme_name, new Command_Message_Handler() ); - $installer->install(); + $installer->install( ! empty( $assoc_args['force'] ) ); } catch ( Exception $e ) { WP_CLI::error( $e->getMessage() ); }