ExportCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 31
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A doExecute() 0 20 2
A configure() 0 4 1
1
<?php
2
3
namespace Startwind\Forrest\CliCommand\Directory;
4
5
use Startwind\Forrest\Util\OutputHelper;
6
use Symfony\Component\Console\Command\Command as SymfonyCommand;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Symfony\Component\Console\Question\ChoiceQuestion;
11
12
class ExportCommand extends DirectoryCommand
13
{
14
    protected static $defaultName = 'directory:export';
15
    protected static $defaultDescription = 'Add an external directory to the list.';
16
17
    protected function configure()
18
    {
19
        parent::configure();
20
        $this->addArgument('directory', InputArgument::OPTIONAL, 'The config string for the directory.');
21
    }
22
23
    protected function doExecute(InputInterface $input, OutputInterface $output): int
24
    {
25
        $selectedDirectoryIdentifier = $input->getArgument('directory');
26
27
        $directories = $this->getDirectoryConfigs();
28
29
        if (!$selectedDirectoryIdentifier) {
30
            /** @var \Symfony\Component\Console\Helper\QuestionHelper $questionHandler */
31
            $questionHandler = $this->getHelper('question');
32
            $selectedDirectoryIdentifier = $questionHandler->ask($input, $output, new ChoiceQuestion('Which directory do you want to export? ', array_keys($directories)));
33
        }
34
35
        $selectedDirectory = $directories[$selectedDirectoryIdentifier];
36
37
        OutputHelper::writeInfoBox($output, 'To import this repository on another machine please use this command:');
38
39
        $output->writeln('  forrest ' . ImportCommand::COMMAND_NAME . ' ' . escapeshellarg($selectedDirectoryIdentifier) . ' ' . escapeshellarg(json_encode($selectedDirectory)));
40
        $output->writeln('');
41
42
        return SymfonyCommand::SUCCESS;
43
    }
44
}
45