From 275d5346b70f0855d3e862a88da9f619c4c46954 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Wed, 20 Sep 2023 12:14:35 -0700 Subject: [PATCH 1/9] Refactor into `get_file_paths_and_names()` function --- src/Dist_Archive_Command.php | 318 +++++++++++++++++++---------------- 1 file changed, 175 insertions(+), 143 deletions(-) diff --git a/src/Dist_Archive_Command.php b/src/Dist_Archive_Command.php index bf486e5..0b900d9 100644 --- a/src/Dist_Archive_Command.php +++ b/src/Dist_Archive_Command.php @@ -65,45 +65,11 @@ class Dist_Archive_Command { * @when before_wp_load */ public function __invoke( $args, $assoc_args ) { - list( $path ) = $args; - $path = rtrim( realpath( $path ), '/' ); - if ( ! is_dir( $path ) ) { - WP_CLI::error( 'Provided input path is not a directory.' ); - } - - $this->checker = new GitIgnoreChecker( $path, '.distignore' ); - if ( isset( $args[1] ) ) { - // If the end of the string is a filename (file.ext), use it for the output archive filename. - if ( 1 === preg_match( '/^[a-zA-Z0-9](?:[a-zA-Z0-9._-]*[a-zA-Z0-9])?\.[a-zA-Z0-9_-]+$/', basename( $args[1] ) ) ) { - $archive_filename = basename( $args[1] ); + list( $source_dir_path, $destination_dir_path, $archive_file_name, $archive_output_dir_name ) = $this->get_file_paths_and_names( $args, $assoc_args ); - // If only the filename was supplied, use the plugin's parent directory for output. - if ( basename( $args[1] ) === $args[1] ) { - $archive_path = dirname( $path ); - } else { - // Otherwise use the supplied directory. - $archive_path = dirname( $args[1] ); - } - } else { - $archive_path = $args[1]; - $archive_filename = null; - } - } else { - if ( 0 !== strpos( $path, '/' ) ) { - $archive_path = dirname( getcwd() . '/' . $path ); - } else { - $archive_path = dirname( $path ); - } - $archive_filename = null; - } - - // If the path is not absolute, it is relative. - if ( 0 !== strpos( $archive_path, '/' ) ) { - $archive_path = rtrim( getcwd() . '/' . ltrim( $archive_path, '/' ), '/' ); - } - - $dist_ignore_filepath = $path . '/.distignore'; + $this->checker = new GitIgnoreChecker( $source_dir_path, '.distignore' ); + $dist_ignore_filepath = $source_dir_path . '/.distignore'; if ( file_exists( $dist_ignore_filepath ) ) { $file_ignore_rules = explode( PHP_EOL, file_get_contents( $dist_ignore_filepath ) ); } else { @@ -111,59 +77,12 @@ public function __invoke( $args, $assoc_args ) { $file_ignore_rules = []; } - $source_base = basename( $path ); - $archive_base = isset( $assoc_args['plugin-dirname'] ) ? rtrim( $assoc_args['plugin-dirname'], '/' ) : $source_base; - - $version = ''; - - /** - * If the path is a theme (meaning it contains a style.css file) - * parse the theme's version from the headers using a regex pattern. - * The pattern used is extracted from the get_file_data() function in core. - * - * @link https://developer.wordpress.org/reference/functions/get_file_data/ - */ - if ( file_exists( $path . '/style.css' ) ) { - $contents = file_get_contents( $path . '/style.css', false, null, 0, 5000 ); - $contents = str_replace( "\r", "\n", $contents ); - $pattern = '/^' . preg_quote( 'Version', ',' ) . ':(.*)$/mi'; - if ( preg_match( $pattern, $contents, $match ) && $match[1] ) { - $version = trim( preg_replace( '/\s*(?:\*\/|\?>).*/', '', $match[1] ) ); - } - } - - if ( empty( $version ) ) { - foreach ( glob( $path . '/*.php' ) as $php_file ) { - $contents = file_get_contents( $php_file, false, null, 0, 5000 ); - $version = $this->get_version_in_code( $contents ); - if ( ! empty( $version ) ) { - $version = trim( $version ); - break; - } - } - } - - if ( empty( $version ) && file_exists( $path . '/composer.json' ) ) { - $composer_obj = json_decode( file_get_contents( $path . '/composer.json' ) ); - if ( ! empty( $composer_obj->version ) ) { - $version = trim( $composer_obj->version ); - } - } - - if ( ! empty( $version ) && false !== stripos( $version, '-alpha' ) && is_dir( $path . '/.git' ) ) { - $response = WP_CLI::launch( "cd {$path}; git log --pretty=format:'%h' -n 1", false, true ); - $maybe_hash = trim( $response->stdout ); - if ( $maybe_hash && 7 === strlen( $maybe_hash ) ) { - $version .= '-' . $maybe_hash; - } - } - - if ( $archive_base !== $source_base || $this->is_path_contains_symlink( $path ) ) { - $tmp_dir = sys_get_temp_dir() . '/' . uniqid( "{$archive_base}.{$version}" ); - $new_path = $tmp_dir . DIRECTORY_SEPARATOR . $archive_base; + if ( basename( $source_dir_path ) !== $archive_output_dir_name || $this->is_path_contains_symlink( $source_dir_path ) ) { + $tmp_dir = sys_get_temp_dir() . '/' . uniqid( $archive_file_name ); + $new_path = "{$tmp_dir}/{$archive_output_dir_name}"; mkdir( $new_path, 0777, true ); - foreach ( $this->get_file_list( $path ) as $relative_filepath ) { - $source_item = $path . $relative_filepath; + foreach ( $this->get_file_list( $source_dir_path ) as $relative_filepath ) { + $source_item = $source_dir_path . $relative_filepath; if ( is_dir( $source_item ) ) { mkdir( "{$new_path}/{$relative_filepath}", 0777, true ); } else { @@ -172,49 +91,23 @@ public function __invoke( $args, $assoc_args ) { } $source_path = $new_path; } else { - $source_path = $path; + $source_path = $source_dir_path; } - if ( is_null( $archive_filename ) ) { - - if ( ! empty( $version ) ) { - if ( ! empty( $assoc_args['filename-format'] ) ) { - $archive_filename = str_replace( [ '{name}', '{version}' ], [ $archive_base, $version ], $assoc_args['filename-format'] ); - } else { - $archive_filename = $archive_base . '.' . $version; - } - } else { - $archive_filename = $archive_base; - } - - if ( 'zip' === $assoc_args['format'] ) { - $archive_filename .= '.zip'; - } elseif ( 'targz' === $assoc_args['format'] ) { - $archive_filename .= '.tar.gz'; - } - } - $archive_absolute_filepath = "{$archive_path}/{$archive_filename}"; + $archive_absolute_filepath = "{$destination_dir_path}/{$archive_file_name}"; chdir( dirname( $source_path ) ); - if ( Utils\get_flag_value( $assoc_args, 'create-target-dir' ) ) { - $this->maybe_create_directory( $archive_absolute_filepath ); - } - - if ( ! is_dir( dirname( $archive_path ) ) ) { - WP_CLI::error( "Target directory does not exist: {$archive_path}" ); - } - // If the files are being zipped in place, we need the exclusion rules. // whereas if they were copied for any reasons above, the rules have already been applied. - if ( $source_path !== $path || empty( $file_ignore_rules ) ) { + if ( $source_path !== $source_dir_path || empty( $file_ignore_rules ) ) { if ( 'zip' === $assoc_args['format'] ) { - $cmd = "zip -r '{$archive_absolute_filepath}' {$archive_base}"; + $cmd = "zip -r '{$archive_absolute_filepath}' {$archive_output_dir_name}"; } elseif ( 'targz' === $assoc_args['format'] ) { - $cmd = "tar -zcvf {$archive_absolute_filepath} {$archive_base}"; + $cmd = "tar -zcvf {$archive_absolute_filepath} {$archive_output_dir_name}"; } } else { - $tmp_dir = sys_get_temp_dir() . '/' . uniqid( "{$archive_base}.{$version}" ); + $tmp_dir = sys_get_temp_dir() . '/' . uniqid( $archive_file_name ); mkdir( $tmp_dir, 0777, true ); if ( 'zip' === $assoc_args['format'] ) { $include_list_filepath = $tmp_dir . '/include-file-list.txt'; @@ -232,7 +125,7 @@ function ( $relative_path ) use ( $source_path ) { ) ) ); - $cmd = "zip -r '{$archive_absolute_filepath}' {$archive_base} -i@{$include_list_filepath}"; + $cmd = "zip -r '{$archive_absolute_filepath}' {$archive_output_dir_name} -i@{$include_list_filepath}"; } elseif ( 'targz' === $assoc_args['format'] ) { $exclude_list_filepath = "{$tmp_dir}/exclude-file-list.txt"; $excludes = array_filter( @@ -249,7 +142,7 @@ function ( $ignored_file ) use ( $source_path ) { trim( implode( "\n", $excludes ) ) ); $anchored_flag = ( php_uname( 's' ) === 'Linux' ) ? '--anchored ' : ''; - $cmd = "tar {$anchored_flag} --exclude-from={$exclude_list_filepath} -zcvf {$archive_absolute_filepath} {$archive_base}"; + $cmd = "tar {$anchored_flag} --exclude-from={$exclude_list_filepath} -zcvf {$archive_absolute_filepath} {$archive_output_dir_name}"; } } @@ -266,16 +159,159 @@ function ( $ignored_file ) use ( $source_path ) { } } + /** + * Determine the full paths and names to use from the CLI input. + * + * I.e. the source directory, the output directory, the output filename, and the directory name the archive will + * extract to. + * + * @param non-empty-array $args Source path (required), target (path or name, optional). + * @param array{format:string,plugin-dirname?:string,filename-format?:string,create-target-dir?:string} $assoc_args + * + * @return array $source_dir_path, $destination_dir_path, $destination_archive_name, $archive_output_dir_name + */ + private function get_file_paths_and_names( $args, $assoc_args ) { + + $source_dir_path = realpath( $args[0] ); + if ( ! is_dir( $source_dir_path ) ) { + WP_CLI::error( 'Provided input path is not a directory.' ); + } + + if ( isset( $args[1] ) ) { + $destination_input = $args[1]; + // If the end of the string is a filename (file.ext), use it for the output archive filename. + if ( 1 === preg_match( '/(zip$|tar$|tar.gz$)/', $destination_input ) ) { + $archive_file_name = basename( $destination_input ); + + // If only the filename was supplied, use the plugin's parent directory for output. + if ( basename( $destination_input ) === $destination_input ) { + $destination_dir_path = dirname( $source_dir_path ); + } else { + // Otherwise use the supplied directory. + $destination_dir_path = dirname( $destination_input ); + } + } else { + // Only a path was supplied, not a filename. + $destination_dir_path = $destination_input; + $archive_file_name = null; + } + } else { + // Use the plugin's parent directory for output. + $destination_dir_path = dirname( $source_dir_path ); + $archive_file_name = null; + } + + // Convert relative path to absolute path (check does it begin with e.g. "c:" or "/"). + if ( 1 !== preg_match( '/(^[a-zA-Z]+:|^\/)/', $destination_dir_path ) ) { + $destination_dir_path = getcwd() . '/' . $destination_dir_path; + } + + if ( Utils\get_flag_value( $assoc_args, 'create-target-dir' ) ) { + $this->maybe_create_directory( $destination_dir_path ); + } + + $destination_dir_path = realpath( $destination_dir_path ); + + if ( ! is_dir( $destination_dir_path ) ) { + WP_CLI::error( "Target directory does not exist: {$destination_dir_path}" ); + } + + // Use the optionally supplied plugin-dirname, or use the name of the directory containing the source files. + $archive_output_dir_name = isset( $assoc_args['plugin-dirname'] ) + ? rtrim( $assoc_args['plugin-dirname'], '/' ) + : basename( $source_dir_path ); + + if ( is_null( $archive_file_name ) ) { + + $version = $this->get_version( $source_dir_path ); + + if ( ! empty( $version ) ) { + if ( ! empty( $assoc_args['filename-format'] ) ) { + $archive_file_stem = str_replace( [ '{name}', '{version}' ], [ $archive_output_dir_name, $version ], $assoc_args['filename-format'] ); + } else { + $archive_file_stem = $archive_output_dir_name . '.' . $version; + } + } else { + $archive_file_stem = $archive_output_dir_name; + } + + if ( 'zip' === $assoc_args['format'] ) { + $archive_file_name = $archive_file_stem . '.zip'; + } elseif ( 'targz' === $assoc_args['format'] ) { + $archive_file_name = $archive_file_stem . '.tar.gz'; + } + } + + return [ $source_dir_path, $destination_dir_path, $archive_file_name, $archive_output_dir_name ]; + } + + /** + * Determine the plugin version from style.css, the main plugin .php file, or composer.json. + * + * Append the commit hash to `-alpha` versions. + * + * @param string $source_dir_path + * + * @return string + */ + private function get_version( $source_dir_path ) { + + $version = ''; + + /** + * If the path is a theme (meaning it contains a style.css file) + * parse the theme's version from the headers using a regex pattern. + * The pattern used is extracted from the get_file_data() function in core. + * + * @link https://developer.wordpress.org/reference/functions/get_file_data/ + */ + if ( file_exists( $source_dir_path . '/style.css' ) ) { + $contents = file_get_contents( $source_dir_path . '/style.css', false, null, 0, 5000 ); + $contents = str_replace( "\r", "\n", $contents ); + $pattern = '/^' . preg_quote( 'Version', ',' ) . ':(.*)$/mi'; + if ( preg_match( $pattern, $contents, $match ) && $match[1] ) { + $version = trim( preg_replace( '/\s*(?:\*\/|\?>).*/', '', $match[1] ) ); + } + } + + if ( empty( $version ) ) { + foreach ( glob( $source_dir_path . '/*.php' ) as $php_file ) { + $contents = file_get_contents( $php_file, false, null, 0, 5000 ); + $version = $this->get_version_in_code( $contents ); + if ( ! empty( $version ) ) { + $version = trim( $version ); + break; + } + } + } + + if ( empty( $version ) && file_exists( $source_dir_path . '/composer.json' ) ) { + $composer_obj = json_decode( file_get_contents( $source_dir_path . '/composer.json' ) ); + if ( ! empty( $composer_obj->version ) ) { + $version = trim( $composer_obj->version ); + } + } + + if ( ! empty( $version ) && false !== stripos( $version, '-alpha' ) && is_dir( $source_dir_path . '/.git' ) ) { + $response = WP_CLI::launch( "cd {$source_dir_path}; git log --pretty=format:'%h' -n 1", false, true ); + $maybe_hash = trim( $response->stdout ); + if ( $maybe_hash && 7 === strlen( $maybe_hash ) ) { + $version .= '-' . $maybe_hash; + } + } + + return $version; + } + /** * Create the directory for a target file if it does not exist yet. * - * @param string $archive_file Path and filename of the target file. + * @param string $destination_dir_path Directory path for the target file. * @return void */ - private function maybe_create_directory( $archive_file ) { - $directory = dirname( $archive_file ); - if ( ! is_dir( $directory ) ) { - mkdir( $directory, $mode = 0777, $recursive = true ); + private function maybe_create_directory( $destination_dir_path ) { + if ( ! is_dir( $destination_dir_path ) ) { + mkdir( $destination_dir_path, $mode = 0777, $recursive = true ); } } @@ -385,18 +421,18 @@ protected function escapeshellcmd( $cmd, $whitelist ) { * If the plugin contains a symlink, we will first copy it to a temp directory, potentially omitting any * symlinks that are excluded via the `.distignore` file, avoiding recursive loops as described in #57. * - * @param string $path The filepath to the directory to check. + * @param string $source_dir_path The path to the directory to check. * * @return bool */ - protected function is_path_contains_symlink( $path ) { + protected function is_path_contains_symlink( $source_dir_path ) { - if ( ! is_dir( $path ) ) { - throw new Exception( 'Path `' . $path . '` is not a directory' ); + if ( ! is_dir( $source_dir_path ) ) { + throw new Exception( 'Path `' . $source_dir_path . '` is not a directory' ); } $iterator = new RecursiveIteratorIterator( - new RecursiveDirectoryIterator( $path, RecursiveDirectoryIterator::SKIP_DOTS ), + new RecursiveDirectoryIterator( $source_dir_path, RecursiveDirectoryIterator::SKIP_DOTS ), RecursiveIteratorIterator::SELF_FIRST ); @@ -417,21 +453,17 @@ protected function is_path_contains_symlink( $path ) { * * Exclude list should contain directory names when no files in that directory exist in the include list. * - * @param string $path Path to process. + * @param string $source_dir_path Path to process. * @param bool $excluded Whether to return the list of files to exclude. Default (false) returns the list of files to include. * @return string[] Filtered list of files to include or exclude (depending on $excluded flag). */ - private function get_file_list( $path, $excluded = false ) { + private function get_file_list( $source_dir_path, $excluded = false ) { $included_files = []; $excluded_files = []; - if ( ! is_dir( $path ) ) { - throw new Exception( "Path '{$path}' is not a directory." ); - } - $iterator = new RecursiveIteratorIterator( - new RecursiveDirectoryIterator( $path, RecursiveDirectoryIterator::SKIP_DOTS ), + new RecursiveDirectoryIterator( $source_dir_path, RecursiveDirectoryIterator::SKIP_DOTS ), RecursiveIteratorIterator::SELF_FIRST ); @@ -440,7 +472,7 @@ private function get_file_list( $path, $excluded = false ) { * @var SplFileInfo $item */ foreach ( $iterator as $item ) { - $relative_filepath = str_replace( $path, '', $item->getPathname() ); + $relative_filepath = str_replace( $source_dir_path, '', $item->getPathname() ); if ( $this->checker->isPathIgnored( $relative_filepath ) ) { $excluded_files[] = $relative_filepath; } else { @@ -448,9 +480,9 @@ private function get_file_list( $path, $excluded = false ) { } } - // Check all excluded directories and remove the from the excluded list if they contain included files. + // Check all excluded directories and remove them from the excluded list if they contain included files. foreach ( $excluded_files as $excluded_file_index => $excluded_relative_path ) { - if ( ! is_dir( $path . $excluded_relative_path ) ) { + if ( ! is_dir( $source_dir_path . $excluded_relative_path ) ) { continue; } foreach ( $included_files as $included_relative_path ) { From 83135c97b6e72917b3ebfe30c1febb8f218792c7 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Wed, 20 Sep 2023 16:17:28 -0700 Subject: [PATCH 2/9] Add default `filename-format` in PhpDoc --- src/Dist_Archive_Command.php | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/Dist_Archive_Command.php b/src/Dist_Archive_Command.php index 0b900d9..36064b9 100644 --- a/src/Dist_Archive_Command.php +++ b/src/Dist_Archive_Command.php @@ -59,8 +59,10 @@ class Dist_Archive_Command { * --- * * [--filename-format=] - * : Use a custom format for archive filename. Defaults to '{name}.{version}'. - * This is ignored if a custom filename is provided or version does not exist. + * : Use a custom format for archive filename. Available substitutions: {name}, {version}. + * This is ignored if the parameter is provided or the version cannot be determined. + * --- + * default: "{name}.{version}" * * @when before_wp_load */ @@ -222,18 +224,12 @@ private function get_file_paths_and_names( $args, $assoc_args ) { : basename( $source_dir_path ); if ( is_null( $archive_file_name ) ) { - $version = $this->get_version( $source_dir_path ); - if ( ! empty( $version ) ) { - if ( ! empty( $assoc_args['filename-format'] ) ) { - $archive_file_stem = str_replace( [ '{name}', '{version}' ], [ $archive_output_dir_name, $version ], $assoc_args['filename-format'] ); - } else { - $archive_file_stem = $archive_output_dir_name . '.' . $version; - } - } else { - $archive_file_stem = $archive_output_dir_name; - } + // If the version number has been found, substitute it into the filename-format parameter, or just use the name. + $archive_file_stem = ! empty( $version ) + ? str_replace( [ '{name}', '{version}' ], [ $archive_output_dir_name, $version ], $assoc_args['filename-format'] ) + : $archive_output_dir_name; if ( 'zip' === $assoc_args['format'] ) { $archive_file_name = $archive_file_stem . '.zip'; From 3a3b775ad4c8e7283e69a3137ed0788b63bd8e32 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Wed, 20 Sep 2023 16:21:33 -0700 Subject: [PATCH 3/9] Update doc (whitespace, order, optional, type) --- src/Dist_Archive_Command.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Dist_Archive_Command.php b/src/Dist_Archive_Command.php index 36064b9..1a84140 100644 --- a/src/Dist_Archive_Command.php +++ b/src/Dist_Archive_Command.php @@ -60,7 +60,7 @@ class Dist_Archive_Command { * * [--filename-format=] * : Use a custom format for archive filename. Available substitutions: {name}, {version}. - * This is ignored if the parameter is provided or the version cannot be determined. + * This is ignored if the parameter is provided or the version cannot be determined. * --- * default: "{name}.{version}" * @@ -168,7 +168,7 @@ function ( $ignored_file ) use ( $source_path ) { * extract to. * * @param non-empty-array $args Source path (required), target (path or name, optional). - * @param array{format:string,plugin-dirname?:string,filename-format?:string,create-target-dir?:string} $assoc_args + * @param array{format:string,filename-format:string,plugin-dirname?:string,create-target-dir?:bool} $assoc_args * * @return array $source_dir_path, $destination_dir_path, $destination_archive_name, $archive_output_dir_name */ From 41a1cf29cb2e6362959a9f460286d62fc26c1811 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Wed, 20 Sep 2023 22:02:27 -0700 Subject: [PATCH 4/9] Use ternary for `$destination_dir_path` --- src/Dist_Archive_Command.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Dist_Archive_Command.php b/src/Dist_Archive_Command.php index 1a84140..a41794a 100644 --- a/src/Dist_Archive_Command.php +++ b/src/Dist_Archive_Command.php @@ -185,13 +185,12 @@ private function get_file_paths_and_names( $args, $assoc_args ) { if ( 1 === preg_match( '/(zip$|tar$|tar.gz$)/', $destination_input ) ) { $archive_file_name = basename( $destination_input ); - // If only the filename was supplied, use the plugin's parent directory for output. - if ( basename( $destination_input ) === $destination_input ) { - $destination_dir_path = dirname( $source_dir_path ); - } else { - // Otherwise use the supplied directory. - $destination_dir_path = dirname( $destination_input ); - } + // If only the filename was supplied, use the plugin's parent directory for output, otherwise use + // the supplied directory. + $destination_dir_path = basename( $destination_input ) === $destination_input + ? dirname( $source_dir_path ) + : dirname( $destination_input ); + } else { // Only a path was supplied, not a filename. $destination_dir_path = $destination_input; From 7db245ce084123c1f24db6ad81ba3948d7c41ddc Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Wed, 20 Sep 2023 22:02:46 -0700 Subject: [PATCH 5/9] Use ternary for `$archive_file_name` --- src/Dist_Archive_Command.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Dist_Archive_Command.php b/src/Dist_Archive_Command.php index a41794a..65c38c8 100644 --- a/src/Dist_Archive_Command.php +++ b/src/Dist_Archive_Command.php @@ -230,11 +230,9 @@ private function get_file_paths_and_names( $args, $assoc_args ) { ? str_replace( [ '{name}', '{version}' ], [ $archive_output_dir_name, $version ], $assoc_args['filename-format'] ) : $archive_output_dir_name; - if ( 'zip' === $assoc_args['format'] ) { - $archive_file_name = $archive_file_stem . '.zip'; - } elseif ( 'targz' === $assoc_args['format'] ) { - $archive_file_name = $archive_file_stem . '.tar.gz'; - } + $archive_file_name = 'zip' === $assoc_args['format'] + ? $archive_file_stem . '.zip' + : $archive_file_stem . '.tar.gz'; } return [ $source_dir_path, $destination_dir_path, $archive_file_name, $archive_output_dir_name ]; From ba989194bccb0582fee61137349c40e6d674ba00 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Wed, 20 Sep 2023 22:03:13 -0700 Subject: [PATCH 6/9] Use word "template" not "parameter" in comment --- src/Dist_Archive_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Dist_Archive_Command.php b/src/Dist_Archive_Command.php index 65c38c8..99c9d05 100644 --- a/src/Dist_Archive_Command.php +++ b/src/Dist_Archive_Command.php @@ -225,7 +225,7 @@ private function get_file_paths_and_names( $args, $assoc_args ) { if ( is_null( $archive_file_name ) ) { $version = $this->get_version( $source_dir_path ); - // If the version number has been found, substitute it into the filename-format parameter, or just use the name. + // If the version number has been found, substitute it into the filename-format template, or just use the name. $archive_file_stem = ! empty( $version ) ? str_replace( [ '{name}', '{version}' ], [ $archive_output_dir_name, $version ], $assoc_args['filename-format'] ) : $archive_output_dir_name; From b9c91d2c5eac537f0c89d52de152624f3edd1d5b Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Fri, 22 Sep 2023 19:35:09 -0700 Subject: [PATCH 7/9] Fix return array type --- src/Dist_Archive_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Dist_Archive_Command.php b/src/Dist_Archive_Command.php index 99c9d05..3033222 100644 --- a/src/Dist_Archive_Command.php +++ b/src/Dist_Archive_Command.php @@ -170,7 +170,7 @@ function ( $ignored_file ) use ( $source_path ) { * @param non-empty-array $args Source path (required), target (path or name, optional). * @param array{format:string,filename-format:string,plugin-dirname?:string,create-target-dir?:bool} $assoc_args * - * @return array $source_dir_path, $destination_dir_path, $destination_archive_name, $archive_output_dir_name + * @return string[] $source_dir_path, $destination_dir_path, $destination_archive_name, $archive_output_dir_name */ private function get_file_paths_and_names( $args, $assoc_args ) { From a63f9b9e0e44e5ea71e38a642e2ee84103b7dd54 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Wed, 6 Dec 2023 11:50:02 -0800 Subject: [PATCH 8/9] Add missing closing `---` --- src/Dist_Archive_Command.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Dist_Archive_Command.php b/src/Dist_Archive_Command.php index cef2b92..ac71d48 100644 --- a/src/Dist_Archive_Command.php +++ b/src/Dist_Archive_Command.php @@ -63,6 +63,7 @@ class Dist_Archive_Command { * This is ignored if the parameter is provided or the version cannot be determined. * --- * default: "{name}.{version}" + * --- * * @when before_wp_load */ From d6907b50092a1554f9c5b1b4e2c83b23c8ec5ce8 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Wed, 6 Dec 2023 11:50:12 -0800 Subject: [PATCH 9/9] Regenerate README --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dbb0b37..bbeb63e 100644 --- a/README.md +++ b/README.md @@ -57,8 +57,11 @@ script in each project. --- [--filename-format=] - Use a custom format for archive filename. Defaults to '{name}.{version}'. - This is ignored if a custom filename is provided or version does not exist. + Use a custom format for archive filename. Available substitutions: {name}, {version}. + This is ignored if the parameter is provided or the version cannot be determined. + --- + default: "{name}.{version}" + --- ## Installing