Skip to content

Disable progress bar when not in an interactive terminal #45596

@greg0ire

Description

@greg0ire

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy