title: "WP_CLI\Utils\make_progress_bar()" post_status: publish comment_status: open taxonomy: category: - wp-cli-handbook post_tag: - Internal Api - References - Repos
WP_CLI\Utils\make_progress_bar()
创建一个进度条,用于显示给定操作的完成百分比。
用法
WP_CLI\Utils\make_progress_bar( $message, $count, $interval = 100 )
$message (string) 进度条前显示的文本。
$count (integer) 要执行的总刻度数。
$interval (int) 可选。更新间隔(毫秒)。默认值为 100。
@return (\cli\progress\Bar|\WP_CLI\NoOp)
$count (integer) 要执行的总刻度数。
$interval (int) 可选。更新间隔(毫秒)。默认值为 100。
@return (\cli\progress\Bar|\WP_CLI\NoOp)
Notes
Progress bar is written to STDOUT, and disabled when command is piped. Progress
advances with $progress->tick(), and completes with $progress->finish().
Process bar also indicates elapsed time and expected total time.
# `wp user generate` ticks progress bar each time a new user is created.
#
# $ wp user generate --count=500
# Generating users 22 % [=======> ] 0:05 / 0:23
$progress = \WP_CLI\Utils\make_progress_bar( 'Generating users', $count );
for ( $i = 0; $i < $count; $i++ ) {
// uses wp_insert_user() to insert the user
$progress->tick();
}
$progress->finish();
Internal API documentation is generated from the WP-CLI codebase on every release. To suggest improvements, please submit a pull request.
相关
- WP_CLI\Utils\format_items() - 将项目集合渲染为 ASCII 表格、JSON、CSV、YAML、ID 列表或计数。
- WP_CLI::colorize() - 为输出字符串着色。
- WP_CLI::line() - 显示不带前缀的信息性消息,并忽略 `--quiet`。
- WP_CLI::log() - 显示不带前缀的信息性消息。
- WP_CLI::success() - 显示以“Success: ”为前缀的成功消息。
- WP_CLI::debug() - 当使用 `--debug` 时,显示以“Debug: ”为前缀的调试消息。
- WP_CLI::warning() - 显示以“Warning: ”为前缀的警告消息。
- WP_CLI::error() - 显示以“Error: ”为前缀的错误消息并退出脚本。
- WP_CLI::halt() - 以特定返回代码停止脚本执行。
- WP_CLI::error_multi_line() - 在红色框中显示多行错误消息。不退出脚本。