Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Disable progress bar when not in an interactive terminal #45596

Copy link
Copy link
Open
@greg0ire

Description

@greg0ire
Issue body actions

Description

Progress bars are a great way to provide feedback to somebody using a Symfony command in a terminal. However, when running the same Symfony command in a cronjob, you will often get logs flooded by the output of the same progress bar. I found that in my case, checking for the TERM env variable seemed like a reliable way to do this, and I'm proposing this is done internally by Symfony, transparently.

Example

Before

if (getenv('TERM') !== false) {
    $progressBar = new ProgressBar($output);
    $callback = function () use ($progressBar): void {
        $progressBar->advance();
    };
} else {
	$callback = null;
}     
($this->import)($callback);
if (isset($progressBar)) {
    $progressBar->finish();
}

After

$progressBar = new ProgressBar($output);
$callback = function () use ($progressBar): void {
    $progressBar->advance(); // does nothing if TERM is not set
};
($this->import)($callback);
$progressBar->finish(); // does nothing if TERM is not set

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.