Przeglądaj źródła

Merged in FD3-310 (pull request #15)

FD3-310 Comandos make:version y make:subversion
Guillermo Espinoza 7 lat temu
rodzic
commit
44590e6fb4

+ 2 - 0
tools/cmd.php

@@ -13,5 +13,7 @@ $app->add(new FD3\MergeHostsFile());
 $app->add(new FD3\DockerInventory());
 $app->add(new FD3\ImportClient());
 $app->add(new FD3\Command\ImportONUCommand());
+$app->add(new FD3\Command\MakeVersionCommand());
+$app->add(new FD3\Command\MakeSubversionCommand());
 
 $app->run();

+ 51 - 0
tools/src/Command/MakeSubversionCommand.php

@@ -0,0 +1,51 @@
+<?php
+
+namespace FD3\Command;
+
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+
+use PHPGit\Git;
+use PHPGit\Exception\GitException;
+
+class MakeSubversionCommand extends Command
+{
+    protected function configure()
+    {
+        $this
+        ->setName('make:subversion')
+        ->setDescription('Create a tag with version name')
+        ->setHelp('This command allows you to create a tag with version name in a git repository')
+        ->addArgument('ini_file', InputArgument::REQUIRED, 'The ini file from where to get the source code config.')
+        ->addArgument('version', InputArgument::REQUIRED, 'Version number. e.g. v0.0.1')
+        ;
+    }
+
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        $file = $input->getArgument("ini_file");
+        $version = $input->getArgument("version");
+
+        $realpath = realpath($file);
+        $dirname = dirname($realpath);
+        if (!chdir($dirname)) {
+            throw new \Exception("Can't change working directory to ".$dirname);
+        }
+
+        $content = parse_ini_file($realpath, true);
+        foreach ($content as $sec => $conf) {
+            try {
+                $git = new Git();
+                $git_path = $dirname.'/'.$sec;
+                $git->setRepository($git_path);
+                $git->tag($version);
+            } catch (GitException $e) {
+                $output->write($e->getMessage());
+                throw $e;
+            }
+        }
+    }
+}

+ 52 - 0
tools/src/Command/MakeVersionCommand.php

@@ -0,0 +1,52 @@
+<?php
+
+namespace FD3\Command;
+
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+
+use PHPGit\Git;
+use PHPGit\Exception\GitException;
+
+class MakeVersionCommand extends Command
+{
+    protected function configure()
+    {
+        $this
+        ->setName('make:version')
+        ->setDescription('Create a branch with version name in a git repository')
+        ->setHelp('This command allows you to create a branch with version name in a git repository')
+        ->addArgument('ini_file', InputArgument::REQUIRED, 'The ini file from where to get the source code config.')
+        ->addArgument('version', InputArgument::REQUIRED, 'Version number. e.g. v0.0')
+        ;
+    }
+
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        $file = $input->getArgument("ini_file");
+        $version = $input->getArgument("version");
+
+        $realpath = realpath($file);
+        $dirname = dirname($realpath);
+        if (!chdir($dirname)) {
+            throw new \Exception("Can't change working directory to ".$dirname);
+        }
+
+        $content = parse_ini_file($realpath, true);
+        foreach ($content as $sec => $conf) {
+            try {
+                $git = new Git();
+                $git_path = $dirname.'/'.$sec;
+                $git->setRepository($git_path);
+                $git->branch->create($version);
+                $git->checkout($version);
+            } catch (GitException $e) {
+                $output->write($e->getMessage());
+                throw $e;
+            }
+        }
+    }
+}