Skip to content

Instantly share code, notes, and snippets.

@achraf-jeday
Created April 21, 2020 07:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save achraf-jeday/30945fadafc07848dda0e0c78137e290 to your computer and use it in GitHub Desktop.
Save achraf-jeday/30945fadafc07848dda0e0c78137e290 to your computer and use it in GitHub Desktop.
Progress bar Example: drush command drupal 8
<?php
namespace Drupal\migrate_opm\Commands;
use Drush\Commands\DrushCommands;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* A Drush commandfile.
*
* In addition to this file, you need a drush.services.yml
* in root of your module, and a composer.json file that provides the name
* of the services file to use.
*/
class MigrateOPMCommands extends DrushCommands {
/**
* Constructs a new DepotService object.
*/
public function __construct() {
}
/**
* Main command.
*
* @param \Symfony\Component\Console\Input\InputInterface $input
* Input.
* @param \Symfony\Component\Console\Output\OutputInterface $output
* Output.
*
* @command migrate_opm:progress-bar
* @aliases opm-insert-users
* @usage migrate_opm:insert-users
*/
public function show_progress_bar(InputInterface $input, OutputInterface $output) {
$progressBar = new ProgressBar($output, 100);
$progressBar->start();
for ($i = 1; $i <= 100; $i++) {
usleep(500000);
$progressBar->advance();
}
$progressBar->finish();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment