Thanks to visit codestin.com
Credit goes to github.com

Skip to content

allow access/configuration to SymfonyStyle's progressBar in 7.3 #60381

Open
@tacman

Description

@tacman

Description

As I'm converting my console commands to Symfony 7.3, I've started to tighten them up by using SymfonyStyle's built-in progress bar.

But sometimes I want to customize it, or even just to access it.

Example

    public function __invoke(
        SymfonyStyle     $io,
        #[Option(description: 'batch size for flush')]
        int    $batch = 5,

Before:

         $progressBar = $io->createProgressBar($limit ?: $finder->count());
         $progressBar->start();
         foreach ($io->iterate($finder, $limit ?: $finder->count()) as $idx=>$dir) {
            $progressBar->advance();
            if (($progressBar->getProgress() % $batch) === 0) {
                $this->entityManager->flush();
                $this->entityManager->clear();
            }
          }
          $progressBar->finish(); 

After:

        foreach ($io->progressIterate($finder, $limit ?: $finder->count()) as $idx=>$dir) {
            if (($io->getProgressBar()->getProgress() % $batch) === 0) {
                $this->entityManager->flush();
                $this->entityManager->clear();
            }
    }

I'd also like to configure the progressBar verbosity independently of the command verbosity. I pretty much always want to know how much memory is being used. So maybe something like creating the progressBar and setting it in $io?

I know I can do it by simply creating a progressBar and manually calling the advance and finish, but it's less code to use the built-in one.

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