|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Bowerphp. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Massimiliano Arione <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Bowerphp\Command; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Init |
|
19
|
|
|
*/ |
|
20
|
|
|
class InitCommand extends Command |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* {@inheritdoc} |
|
24
|
|
|
*/ |
|
25
|
|
|
protected function configure() |
|
26
|
|
|
{ |
|
27
|
|
|
$this |
|
28
|
|
|
->setName('init') |
|
29
|
|
|
->setDescription('Initializes a bower.json file') |
|
30
|
|
|
->setHelp(<<<'EOT' |
|
31
|
|
|
The <info>%command.name%</info> command initializes a bower.json file in |
|
32
|
|
|
the current directory. |
|
33
|
|
|
|
|
34
|
|
|
<info>php %command.full_name%</info> |
|
35
|
|
|
EOT |
|
36
|
|
|
) |
|
37
|
|
|
; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* {@inheritdoc} |
|
42
|
|
|
*/ |
|
43
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
44
|
|
|
{ |
|
45
|
|
|
$this->setGithubToken($output); |
|
46
|
|
|
|
|
47
|
|
|
$author = sprintf('%s <%s>', $this->getGitInfo(), $this->getGitInfo('user.email')); |
|
48
|
|
|
|
|
49
|
|
|
$params = ['name' => get_current_user(), 'author' => $author]; |
|
50
|
|
|
|
|
51
|
|
|
// @codeCoverageIgnoreStart |
|
52
|
|
|
if ($input->isInteractive()) { |
|
53
|
|
|
$dialog = $this->getHelperSet()->get('question'); |
|
54
|
|
|
|
|
55
|
|
|
$params['name'] = $dialog->ask( |
|
56
|
|
|
$input, $output, $dialog->getQuestion('Please specify a name for project', $params['name']) |
|
57
|
|
|
); |
|
58
|
|
|
|
|
59
|
|
|
$params['author'] = $dialog->ask( |
|
60
|
|
|
$input, $output, $dialog->getQuestion('Please specify an author', $params['author']) |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
// @codeCoverageIgnoreEnd |
|
64
|
|
|
$bowerphp = $this->getBowerphp($output); |
|
65
|
|
|
$bowerphp->init($params); |
|
66
|
|
|
|
|
67
|
|
|
$output->writeln(''); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Get some info from local git |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $info info type |
|
74
|
|
|
* @return string|null |
|
75
|
|
|
*/ |
|
76
|
|
|
private function getGitInfo($info = 'user.name') |
|
77
|
|
|
{ |
|
78
|
|
|
$output = []; |
|
79
|
|
|
$return = 0; |
|
80
|
|
|
$info = exec("git config --get $info", $output, $return); |
|
81
|
|
|
|
|
82
|
|
|
if (0 === $return) { |
|
83
|
|
|
return $info; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|