Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,16 @@ $ ln -s /path/to/phpqa/bin/phpqa /usr/local/bin/phpqa
### Copy configuration file(s)
```
$ cd to/project/path
$ phpqa init --project=PROJECT --dir=DIR --override
$ phpqa init --project=PROJECT --global --override
```
| Option | Description |
| -------- | ----------------------------- |
| project | Available values `php`, `symfony` and `drupal`. |
| dir | Available values `home`, `current`. |
| global | Copy configuration files to user home directory, instead of current working directory. |
| override | If this option is set, files are copied using override flag. |

**NOTES:**
- Option `global` does not accept a value must be set as `--global`.
- Option `override` does not accept a value must be set as `--override`.

### Analyze a project
Expand Down
39 changes: 15 additions & 24 deletions src/Command/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@ protected function configure()
$this
->setName('init')
->setDescription('Copy configuration files to user home directory')
->addOption(
'dir',
null,
InputOption::VALUE_REQUIRED,
sprintf(
'Directory to copy file(s) valid options (%s)',
implode(',', $this->dirs)
)
)
->addOption(
'project',
null,
Expand All @@ -70,11 +61,17 @@ protected function configure()
implode(',', $this->projects)
)
)
->addOption(
'global',
null,
InputOption::VALUE_NONE,
'Copy configuration files to user home directory, instead of current working directory.'
)
->addOption(
'override',
null,
InputOption::VALUE_NONE,
'Override files on directory'
'Copy files using override flag.'
);
}

Expand All @@ -83,20 +80,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
$application = $this->getApplication();
$config = $application->getConfig();

$dir = $input->getOption('dir');

if (!$dir || !in_array($dir, $this->dirs)) {
throw new \Exception(
sprintf(
'You must provide a valid dir value (%s)',
implode(',', $this->dirs)
)
);
$global = false;
if ($input->hasOption('global')) {
$global = $input->getOption('global');
}

$project = $input->getOption('project');

if ($project && !in_array($project, $this->projects)) {
if (!$project || !in_array($project, $this->projects)) {
throw new \Exception(
sprintf(
'You must provide a valid project value (%s)',
Expand All @@ -110,12 +101,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
$override = $input->getOption('override');
}

if ($dir === 'current') {
$this->copyCurrentDirectory($output, $config, $override, $project);
if ($global) {
$this->copyHomeDirectory($output, $config, $override);
}

if ($dir === 'home') {
$this->copyHomeDirectory($output, $config, $override);
if (!$global) {
$this->copyCurrentDirectory($output, $config, $override, $project);
}
}

Expand Down