Download module command: Adding optional option to download a specific branch

parent 5c3f3750
......@@ -33,6 +33,9 @@ class DownloadModuleCommand extends Command
{
$downloader = new Downloader($this->getOutput());
try {
if ($this->hasOption('branch')) {
$downloader->forBranch($this->option('branch'));
}
$downloader->download($this->argument('name'));
} catch (\Exception $e) {
$this->output->writeln("<error>{$e->getMessage()}</error>");
......@@ -88,6 +91,7 @@ class DownloadModuleCommand extends Command
['seeds', 's', InputOption::VALUE_NONE, 'Run the module seeds', null],
['assets', 'a', InputOption::VALUE_NONE, 'Publish the module assets', null],
['demo', 'd', InputOption::VALUE_NONE, 'Run all optional flags', null],
['branch', null, InputOption::VALUE_OPTIONAL, 'Download a specific branch name', null],
];
}
......
......@@ -27,6 +27,10 @@ class Downloader
* @var string
*/
private $tagName;
/**
* @var string
*/
private $branchName;
public function __construct(OutputInterface $output)
{
......@@ -43,7 +47,7 @@ class Downloader
$this->package = $package;
$latestVersionUrl = $this->getLatestVersionUrl();
$this->output->writeln("<info>Downloading Module [{$this->package} {$this->tagName}]</info>");
$this->output->writeln("<info>Downloading Module [{$this->package} {$this->tagName}{$this->branchName}]</info>");
$directory = config('modules.paths.modules') . '/' . $this->extractPackageNameFrom($package);
......@@ -129,6 +133,9 @@ class Downloader
private function getLatestVersionUrl()
{
if ($this->branchName !== null) {
return "https://github.com/{$this->package}/archive/{$this->branchName}.zip";
}
$client = new Client([
'base_uri' => 'https://api.github.com',
'timeout' => 2.0,
......@@ -153,4 +160,11 @@ class Downloader
}
return studly_case(substr(strrchr($package, '/'), 1));
}
public function forBranch($branchName)
{
$this->branchName = $branchName;
return $this;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment