How to make a command in pimcore

I am looking to set a export command for my code i.e.

$blogs = DataObject\Blogs::getList([]);

    $return_array = array();

    foreach ($blogs as $value) {
        $result = new DataObject\Comments\Listing();
        $result->setCondition("o_parentId = ".$value->getId());

        $all_comments = array();

        foreach ($result as $value1) {
             $all_comments[] = array("Name"=>$value1->getName(),"Comment"=>$value1->getComments(),"Email"=>$value1->getEmail());

        $return_array[] = array("Title"=>$value->getTitle(),"Description"=>$value->getDescription(),"Image"=>$value->getImage(),"comments"=>$all_comments);

    echo json_encode($return_array,JSON_PRETTY_PRINT);


Please help me to create a command that is -> export:command

@rajputram2025 use generator:
bin/console generate:command BundleName export:command

@jplaskonka has a good suggestion. That’s most definitely one way to do it.

But creating commands for Pimcore is actually pretty easy even without using the generator. Just have a look at Symfony commands and make sure your command class extends Pimcore’s AbstractCommand class. Then register it in your services.yml file and you’re all set.