trilbymedia / grav-plugin-git-sync

Collaboratively Synchronize your Grav `user` folder hosted on GitHub, BitBucket or GitLab
Apache License 2.0
243 stars 58 forks source link

Add Initiate CLI command #128

Closed LeonRyan closed 5 years ago

LeonRyan commented 5 years ago

Added a CLI command to initialise git-sync. This is useful for automated deployments and Docker images where git-sync needs to be initialised before first run.

Should close issue #13 .

ghost commented 5 years ago

@LeonRyan cool and very helpful! Would you mind renaming it to InitCommand and the CLI command to init? I think that would align better with the git init command that it essentially performs.

Also the class comment still says LogCommand ๐Ÿ˜‰

ghost commented 5 years ago

Until it's merged, I'm copying the file manually into the Docker image. I have modified your command to look like this:

<?php namespace Grav\Plugin\Console;

use Grav\Console\ConsoleCommand;
use Grav\Plugin\GitSync\GitSync;

/**
 * Class Initommand
 *
 * @package Grav\Plugin\Console
 */
class InitCommand extends ConsoleCommand
{
    protected function configure()
    {
        $this
            ->setName('init')
            ->setDescription('Initializes your git repository')
            ->setHelp('The <info>init</info> command runs the same git commands as the onAdminAfterSave function. Use this to manually initialise git-sync (useful for automated deployments).')
        ;
    }

    protected function serve()
    {
        require_once __DIR__ . '/../vendor/autoload.php';

        $plugin = new GitSync();
        $repository = $plugin->getConfig('repository', false);

        $this->output->writeln('');

        if (!$repository) {
            $this->output->writeln('<red>ERROR:</red> No repository has been configured');
        }

        $this->output->writeln('Initialising <cyan>' . $repository . '</cyan>');

        $this->output->write('Starting Initialisation...');

        $plugin->initializeRepository();
        $plugin->setUser();
        $plugin->addRemote();

        $this->output->writeln('completed.');
    }
}
w00fz commented 5 years ago

Thanks guys. This looks good, agreed that init is nicer.

Iโ€™ll review, apply @alex-mohemian changes and merge in the next coming days!

w00fz commented 5 years ago

All changed and merged now. Thanks!

๐ŸŽ‰

ghost commented 5 years ago

Neat! ๐Ÿ˜„ That makes my Docker images even slimmer.

ghost commented 5 years ago

@w00fz I was a bit hasty when I fixed the class comment and I see you also did not notice the mistake.

https://github.com/trilbymedia/grav-plugin-git-sync/blob/1443cde02237315ebc7aba8132cf6aa84e876261/cli/InitCommand.php#L7

This should obviously be InitCommand. The spelling was also mixed British/American. I have fixed all of these in https://github.com/trilbymedia/grav-plugin-git-sync/pull/132

w00fz commented 5 years ago

Oops! Thanks, I merged. Iโ€™ll probably wait next release cycle though as itโ€™s relatively minor.