Register/add custom Command for deployer

15 Views Asked by At

Im would like to find a way to add or register a new command for my deployer project

Use case :

add FooCommand somewhere in the code (hook or whatever)

Then when i ask dep in my terminal the list of available command print my FooCommand as avalaible

I know i can work with task but task wont work in my case, because i would like to create a command to connect to a MySQL console or Postgres console and when i use task for this i cant interact with my terminal to send sql request. So i would like use a Command like SshCommand to do this.

Thanks for all

I trie to use a task :

task('db:console', function() {
    $conf = getDbConnectionConf(get('WEBAPP_ROOT_PATH'), get('prestashop_version'));
    dump("A");
    if (isset($conf['user'])) {
        $command = "mysql";

        $user = $conf['user'];
        $host = $conf['host'];
        $password = $conf['password'];
        $database = $conf['database'];
        $port = $conf['port'];

        if (isset($conf['host'])) {
            $command = sprintf("%s -h%s", $command, $host);
        }

        if (isset($conf['port'])) {
            $command = sprintf("%s -P%s", $command, $port);
        }
    }
    $command = sprintf("%s -u%s -p%s %s", $command, $user, $password, $database);

    $commandMysql = sprintf("mysql -u%s -p%s -h%s %s", $user, $password, $host, $database);

    run($commandMysql, ["tty" => true]);
})->desc('Open database console');

but cant interact with mysql console

I tried to add command to the application a the top of my deploy.php file :

<?php

declare(strict_types=1);

/*
 * This file is part of the alximy corporate website.
 *
 * Copyright (c) 2021 alximy
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Deployer;

use Symfony\Component\Console\Input\InputOption;

require_once __DIR__.'/vendor/autoload.php';
require_once __DIR__ . '/deployer/Command/DbCommand.php';
Deployer::get()->getConsole()->add(new \Deployer\Command\DbCommand(Deployer::get()));

require 'recipe/common.php';
require 'contrib/rsync.php';

but i got an error :

 Error  in TextDescriptor.php on line 327:

  Call to undefined method Symfony\Component\Console\Helper\Helper::width()

0

There are 0 best solutions below