Created
April 21, 2020 07:02
-
-
Save achraf-jeday/30945fadafc07848dda0e0c78137e290 to your computer and use it in GitHub Desktop.
Progress bar Example: drush command drupal 8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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