diff --git a/src/Util/FormatUtil.php b/src/Util/FormatUtil.php index 159728a..de11ac6 100644 --- a/src/Util/FormatUtil.php +++ b/src/Util/FormatUtil.php @@ -11,7 +11,6 @@ use Toolkit\Cli\ColorTag; use Toolkit\Stdlib\Arr\ArrayHelper; -use Toolkit\Stdlib\Helper\Format; use Toolkit\Stdlib\Helper\JsonHelper; use Toolkit\Stdlib\Str; use Toolkit\Sys\Sys; @@ -25,6 +24,7 @@ use function is_int; use function is_numeric; use function is_scalar; +use function preg_match; use function rtrim; use function str_repeat; use function str_replace; @@ -136,9 +136,12 @@ public static function wrapText(string $text, int $indent = 0, int $width = 0): } /** + * Align command option names. + * * @param array $options * * @return array + * @deprecated Please use {@see FlagUtil::alignOptions()} */ public static function alignOptions(array $options): array { @@ -146,9 +149,9 @@ public static function alignOptions(array $options): array return []; } - // e.g '-h, --help' - $hasShort = (bool)strpos(implode('', array_keys($options)), ','); - if (!$hasShort) { + // check has short option. e.g '-h, --help' + $nameString = implode('|', array_keys($options)); + if (preg_match('/\|-\w/', $nameString) !== 1) { return $options; } @@ -171,34 +174,6 @@ public static function alignOptions(array $options): array return $formatted; } - /** - * ``` - * FormatUtil::memoryUsage(memory_get_usage(true)); - * ``` - * - * @param float|int $memory - * - * @return string - * @deprecated use Format::memory($secs); - */ - public static function memoryUsage(float|int $memory): string - { - return Format::memory($memory); - } - - /** - * format timestamp to how long ago - * - * @param int $secs - * - * @return string - * @deprecated use Format::howLongAgo($secs); - */ - public static function howLongAgo(int $secs): string - { - return Format::howLongAgo($secs); - } - /** * Splice array * diff --git a/src/Util/Helper.php b/src/Util/Helper.php index 4c009e0..216a3f9 100644 --- a/src/Util/Helper.php +++ b/src/Util/Helper.php @@ -13,7 +13,6 @@ use Inhere\Console\Concern\RuntimeProfileTrait; use Inhere\Console\ConsoleConst; use InvalidArgumentException; -use Iterator; use RecursiveCallbackFilterIterator; use RecursiveDirectoryIterator; use RecursiveIteratorIterator; diff --git a/src/Util/ProgressBar.php b/src/Util/ProgressBar.php index bca6f6b..ec29ee3 100644 --- a/src/Util/ProgressBar.php +++ b/src/Util/ProgressBar.php @@ -595,7 +595,7 @@ private static function loadDefaultParsers(): array return $display; }, 'elapsed' => static function (self $bar) { - return FormatUtil::howLongAgo(time() - $bar->getStartTime()); + return Format::howLongAgo(time() - $bar->getStartTime()); }, 'remaining' => static function (self $bar) { if (!$bar->getMaxSteps()) { @@ -609,7 +609,7 @@ private static function loadDefaultParsers(): array $remaining = (int)round((time() - $bar->getStartTime()) / $progress * ($bar->getMaxSteps() - $progress)); } - return FormatUtil::howLongAgo($remaining); + return Format::howLongAgo($remaining); }, 'estimated' => static function (self $bar) { if (!$bar->getMaxSteps()) { @@ -623,7 +623,7 @@ private static function loadDefaultParsers(): array $estimated = (int)round((time() - $bar->getStartTime()) / $bar->getProgress() * $bar->getMaxSteps()); } - return FormatUtil::howLongAgo($estimated); + return Format::howLongAgo($estimated); }, 'memory' => static function () { return Format::memory(memory_get_usage(true));