Skip to content

Commit

Permalink
[generate:profile] Add base-path option (#3524)
Browse files Browse the repository at this point in the history
  • Loading branch information
hjuarez20 authored and jmolivas committed Oct 28, 2017
1 parent 8349aa9 commit 1180442
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
35 changes: 33 additions & 2 deletions src/Command/Generate/ProfileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ protected function configure()
InputOption::VALUE_REQUIRED,
$this->trans('commands.generate.profile.options.machine-name')
)
->addOption(
'base-path',
null,
InputOption::VALUE_REQUIRED,
$this->trans('commands.generate.profile.options.base-path')
)
->addOption(
'description',
null,
Expand Down Expand Up @@ -140,17 +146,18 @@ protected function execute(InputInterface $input, OutputInterface $output)

$profile = $this->validator->validateModuleName($input->getOption('profile'));
$machine_name = $this->validator->validateMachineName($input->getOption('machine-name'));
$base_path = $this->appRoot . $input->getOption('base-path');
$base_path = $this->validator->validateModulePath($base_path, true);
$description = $input->getOption('description');
$core = $input->getOption('core');
$dependencies = $this->validator->validateExtensions($input->getOption('dependencies'), 'module', $io);
$themes = $this->validator->validateExtensions($input->getOption('themes'), 'theme', $io);
$distribution = $input->getOption('distribution');
$profile_path = $this->appRoot . '/profiles';

$this->generator->generate(
$profile,
$machine_name,
$profile_path,
$base_path,
$description,
$core,
$dependencies,
Expand Down Expand Up @@ -209,6 +216,30 @@ function ($machine_name) use ($validators) {
$input->setOption('machine-name', $machine_name);
}

$base_path = $input->getOption('base-path');
if (!$base_path) {
$drupalRoot = $this->appRoot;
$base_path = $io->ask(
$this->trans('commands.generate.profile.questions.base-path'),
'/profiles',
function ($base_path) use ($drupalRoot, $machine_name) {
$base_path = ($base_path[0] != '/' ? '/' : '').$base_path;
$fullPath = $drupalRoot.$base_path.'/'.$machine_name;
if (file_exists($fullPath)) {
throw new \InvalidArgumentException(
sprintf(
$this->trans('commands.generate.profile.errors.directory-exists'),
$fullPath
)
);
}

return $base_path;
}
);
}
$input->setOption('base-path', $base_path);

$description = $input->getOption('description');
if (!$description) {
$description = $io->ask(
Expand Down
4 changes: 2 additions & 2 deletions src/Generator/ProfileGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class ProfileGenerator extends Generator
public function generate(
$profile,
$machine_name,
$profile_path,
$base_path,
$description,
$core,
$dependencies,
$themes,
$distribution
) {
$dir = $profile_path . '/' . $machine_name;
$dir = $base_path . '/' . $machine_name;

if (file_exists($dir)) {
if (!is_dir($dir)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function validateModulePath($module_path, $create = false)
)
);
}

chmod($module_path, 0755);
return $module_path;
}

Expand Down

0 comments on commit 1180442

Please sign in to comment.