@@ -46,6 +46,9 @@ class Dist_Archive_Command {
4646 * [--create-target-dir]
4747 * : Automatically create the target directory as needed.
4848 *
49+ * [--force]
50+ * : Forces overwriting of the archive file if it already exists.
51+ *
4952 * [--plugin-dirname=<plugin-slug>]
5053 * : Set the archive extract directory name. Defaults to project directory name.
5154 *
@@ -100,20 +103,23 @@ public function __invoke( $args, $assoc_args ) {
100103 $ archive_absolute_filepath = "{$ destination_dir_path }/ {$ archive_file_name }" ;
101104
102105 if ( file_exists ( $ archive_absolute_filepath ) ) {
103- WP_CLI ::warning ( 'Archive file already exists ' );
104- WP_CLI ::log ( $ archive_absolute_filepath );
105- $ answer = \cli \prompt (
106- 'Do you want to skip or replace it with a new archive? ' ,
107- $ default = false ,
108- $ marker = ' [s/r]: '
109- );
110- $ should_overwrite = 'r ' === strtolower ( $ answer );
106+ $ should_overwrite = Utils \get_flag_value ( $ assoc_args , 'force ' );
107+ if ( ! $ should_overwrite ) {
108+ WP_CLI ::warning ( 'Archive file already exists ' );
109+ WP_CLI ::log ( $ archive_absolute_filepath );
110+ $ answer = \cli \prompt (
111+ 'Do you want to skip or replace it with a new archive? ' ,
112+ $ default = false ,
113+ $ marker = ' [s/r]: '
114+ );
115+ $ should_overwrite = 'r ' === strtolower ( $ answer );
116+ }
111117 if ( ! $ should_overwrite ) {
112118 WP_CLI ::log ( 'Skipping ' . PHP_EOL );
113119 WP_CLI ::log ( 'Archive generation skipped. ' );
114120 exit ( 0 );
115121 }
116- WP_CLI ::log ( ' Replacing ' . PHP_EOL );
122+ WP_CLI ::log ( " Replacing $ archive_absolute_filepath " . PHP_EOL );
117123 }
118124
119125 chdir ( dirname ( $ source_path ) );
0 commit comments