---
title: "How to Add a Progress Bar using Custom CLI Command in Magento 2?"
url: "https://magecomp.com/blog/add-progress-bar-using-custom-cli-command-magento-2/"
date: "2021-10-11T14:27:47+00:00"
modified: "2025-02-17T07:03:34+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 545
reading_time: "3 min read"
summary: "Hello Magento Friends,"
description: "A progress bar is very useful to indicate to the user about the process. Learn How to Add a Progress Bar using Custom CLI Command in Magento 2."
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Get Products by ID using REST API in Magento 2"
    url: "https://magecomp.com/blog/get-products-by-id-using-rest-api-magento-2/"
  - title: "How to Change Category Page Layout for Specific Category Only in Magento 2?"
    url: "https://magecomp.com/blog/change-category-page-layout-for-specific-category-magento-2/"
  - title: "Magento 2: How to Display Product Image on Admin Order Create Page"
    url: "https://magecomp.com/blog/magento-2-display-product-image-on-admin-order-create-page/"
---

# How to Add a Progress Bar using Custom CLI Command in Magento 2?

_Published: October 11, 2021_  
_Author: Dhiren Vasoya_  

![How to Add a Progress Bar using Custom CLI Command in Magento 2](https://magecomp.com/blog/wp-content/uploads/2021/10/How-to-Add-a-Progress-Bar-using-Custom-CLI-Command-in-Magento-2-1-1024x512.webp)

**Hello Magento Friends,**

In today’s article, we will learn about How to Add a Progress Bar using Custom CLI Command in Magento 2.
Sometimes a customer needs to wait for the process to be completed while working with Magento. A progress bar is used when you want to indicate to the customer about the process and its status.
[![hyva theme development](https://magecomp.com/blog/wp-content/uploads/2025/02/hyva-theme-development-CTA-5.webp)](https://magecomp.com/services/hyva-theme-development/)

You can create a progress bar using custom CLI commands in Magento 2. Let’s learn how
## Steps to Add a Progress Bar using Custom CLI Command in Magento 2:
**Step 1:** Navigate to the below path
**app\code\Vendor\Extension\etc\di.xml**

Now, add the below code
```
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="MagentoFrameworkConsoleCommandListInterface">
        <arguments>
            <argument name="commands" xsi:type="array">
                <item name="vendor_progress_bar" xsi:type="object">VendorExtensionConsoleCommandProgressBarCommand</item>
            </argument>
        </arguments>
    </type>
    <type name="VendorExtensionConsoleCommandProgressBarCommand">
        <arguments>
            <argument name="name" xsi:type="string">magecomp:custom:progress-bar</argument>
        </arguments>
    </type>
</config>
```

**Step 2:** Then go to the following path
**app\code\Vendor\Extension\Console\Command\ProgressBar.php**

Then move to the below path
```
<?php

namespace VendorExtensionConsoleCommand;

use MagentoDirectoryModelResourceModelCountryCollectionFactory;
use MagentoFrameworkConsoleCli;
use SymfonyComponentConsoleCommandCommand;
use SymfonyComponentConsoleHelperProgressBar;
use SymfonyComponentConsoleHelperProgressBarFactory;
use SymfonyComponentConsoleInputInputInterface;
use SymfonyComponentConsoleOutputOutputInterface;

class ProgressBar extends Command
{
    /**
     * @var ProgressBarFactory
     */
    private $progressBarFactory;

    /**
     * @var CollectionFactory
     */
    protected $_customer;

    protected $_customerFactory;

    /**
     * @inheritDoc
     */
    public function __construct(
        ProgressBarFactory $progressBarFactory,
        MagentoCustomerModelCustomerFactory $customerFactory,
        MagentoCustomerModelCustomer $customers,
        string $name
    ) {
        $this->progressBarFactory = $progressBarFactory;
        $this->_customerFactory = $customerFactory;
        $this->_customer = $customers;

        parent::__construct($name);
    }

    /**
     * @inheritDoc
     */
    protected function configure()
    {
        parent::configure();
    }

    /**
     * Execute the command
     *
     * @param InputInterface $input
     * @param OutputInterface $output
     *
     * @return int
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $output->writeln('<info>Execution starts.</info>');

        $customercollection = $this->_customer->getCollection()->addAttributeToSelect("*")->load();

        /** @var ProgressBar $progress */
        $progressBar = $this->progressBarFactory->create(
            [
                'output' => $output,
                'max' => count($customercollection),
            ]
        );

        $progressBar->setFormat(
            'Customer/Collection    %current%/%max% %bar% %percent:3s%% %elapsed% %memory:6s%'
        );

        $progressBar->start();

        foreach ($customercollection as $customer) {

           /* Add your custom functionality here */

            $progressBar->advance();
        }

        $progressBar->finish();
        $output->write(PHP_EOL);
        $output->writeln('<info>Execution ends.</info>');

        return Cli::RETURN_SUCCESS;
    }
}
```

[![Hire Magento Programmer](https://magecomp.com/blog/wp-content/uploads/2025/02/Hire-Magento-Programmer-CTA-1.webp)](https://magecomp.com/services/hire-magento-programmer/)

**Step 3:** After that run the below commands
```
php bin/magento c:c
php bin/magento c:f
```

Now, you need to run the below command in Magento root:
```
sudo php bin/magento  magecomp:custom:progress-bar
```

The output will be as follows in the terminal after executing the above command.
[![progress bar](https://magecomp.com/blog/wp-content/uploads/2021/10/progress-bar.png)](https://magecomp.com/blog/wp-content/uploads/2021/10/progress-bar.png)

## Conclusion:
This way you can Add a Progress Bar using Custom CLI Command in Magento 2. Check out the [**list of useful CLI Commands**](https://magecomp.com/blog/magento-2-cli-ssh-commands/). If you face any obstacles, let me know via the comment part. Share the article with your developer friends. Stay tuned with us for another Magento solution.
[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-2-2.webp)](https://magecomp.com/services/magento-upgrade-services/)

**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/add-progress-bar-using-custom-cli-command-magento-2/](https://magecomp.com/blog/add-progress-bar-using-custom-cli-command-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-05 07:55:39 UTC_  
