10000 Disable progress bar when not in an interactive terminal · Issue #45596 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Disable progress bar when not in an interactive terminal #45596
Open
@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

      0