1
|
|
|
<?php |
2
|
|
|
namespace keeko\tools\ui; |
3
|
|
|
|
4
|
|
|
use keeko\framework\schema\PackageSchema; |
5
|
|
|
use keeko\tools\helpers\InitCommandHelperTrait; |
6
|
|
|
use Symfony\Component\Console\Command\Command; |
7
|
|
|
use Symfony\Component\Console\Question\Question; |
8
|
|
|
|
9
|
|
|
class InitUI extends AbstractUI { |
10
|
|
|
|
11
|
|
|
use InitCommandHelperTrait; |
12
|
|
|
|
13
|
|
|
/** @var PackageSchema */ |
14
|
|
|
private $package; |
|
|
|
|
15
|
|
|
|
16
|
|
|
|
17
|
|
|
public function show() { |
|
|
|
|
18
|
|
|
$input = $this->io->getInput(); |
19
|
|
|
$output = $this->io->getOutput(); |
20
|
|
|
$force = $input->getOption('force'); |
21
|
|
|
$formatter = $this->command->getHelperSet()->get('formatter'); |
22
|
|
|
$output->writeln([ |
23
|
|
|
'', |
24
|
|
|
$formatter->formatBlock('Welcome to the Keeko initializer', 'bg=blue;fg=white', true), |
25
|
|
|
'' |
26
|
|
|
]); |
27
|
|
|
$output->writeln([ |
28
|
|
|
'', |
29
|
|
|
'This command will guide you through creating your Keeko composer package.', |
30
|
|
|
'', |
31
|
|
|
]); |
32
|
|
|
|
33
|
|
|
$package = $this->getService()->getPackageService()->getPackage(); |
34
|
|
|
|
35
|
|
|
$name = $this->getPackageName(); |
36
|
|
|
$askName = $name === null; |
37
|
|
|
if ($name === null) { |
38
|
|
|
$git = $this->getGitConfig(); |
39
|
|
|
$cwd = realpath("."); |
|
|
|
|
40
|
|
|
$name = basename($cwd); |
41
|
|
|
$name = preg_replace('{(?:([a-z])([A-Z])|([A-Z])([A-Z][a-z]))}', '\\1\\3-\\2\\4', $name); |
42
|
|
|
$name = strtolower($name); |
43
|
|
|
$localName = $package->getFullName(); |
44
|
|
|
if (!empty($localName)) { |
45
|
|
|
$name = $package->getFullName(); |
46
|
|
|
} else if (isset($git['github.user'])) { |
47
|
|
|
$name = $git['github.user'] . '/' . $name; |
48
|
|
|
} elseif (!empty($_SERVER['USERNAME'])) { |
49
|
|
|
$name = $_SERVER['USERNAME'] . '/' . $name; |
50
|
|
|
} elseif (get_current_user()) { |
51
|
|
|
$name = get_current_user() . '/' . $name; |
52
|
|
|
} else { |
53
|
|
|
// package names must be in the format foo/bar |
54
|
|
|
$name = $name . '/' . $name; |
55
|
|
|
} |
56
|
|
|
} else { |
57
|
|
|
$this->validateName($name); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
// asking for the name |
61
|
|
|
if ($askName || $force) { |
62
|
|
|
$name = $this->askQuestion(new Question('Package name (<vendor>/<name>)', $name)); |
63
|
|
|
$this->validateName($name); |
64
|
|
|
$input->setOption('name', $name); |
65
|
|
|
$package->setFullName($name); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
// asking for a description |
69
|
|
|
$desc = $this->getPackageDescription(); |
70
|
|
|
if ($desc === null || $force) { |
71
|
|
|
$desc = $this->askQuestion(new Question('Description', $desc)); |
72
|
|
|
$input->setOption('description', $desc); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
// asking for the author |
76
|
|
|
if ($package->getAuthors()->isEmpty() || $force) { |
77
|
|
|
$author = $input->getOption('author'); |
78
|
|
|
if ($author === null && isset($git['user.name'])) { |
79
|
|
|
$author = $git['user.name']; |
80
|
|
|
|
81
|
|
|
if (isset($git['user.email'])) { |
82
|
|
|
$author = sprintf('%s <%s>', $git['user.name'], $git['user.email']); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$author = $this->askQuestion(new Question('Author', $author)); |
87
|
|
|
$input->setOption('author', $author); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
// asking for the package type |
91
|
|
|
$type = $this->getPackageType(); |
92
|
|
|
if ($type === null || $force) { |
93
|
|
|
$types = ['module', 'app']; |
94
|
|
|
$question = new Question('Package type (module|app)', $type); |
95
|
|
|
$question->setAutocompleterValues($types); |
96
|
|
|
$question->setValidator(function($answer) use ($types) { |
97
|
|
|
if (!in_array($answer, $types)) { |
98
|
|
|
throw new \RuntimeException('The name of the type should be one of: ' . |
99
|
|
|
implode(',', $types)); |
100
|
|
|
} |
101
|
|
|
return $answer; |
102
|
|
|
}); |
103
|
|
|
$question->setMaxAttempts(2); |
104
|
|
|
$type = $this->askQuestion($question); |
105
|
|
|
} |
106
|
|
|
$input->setOption('type', $type); |
107
|
|
|
|
108
|
|
|
// asking for the license |
109
|
|
|
$license = $this->getPackageLicense(); |
110
|
|
|
if ($license === null || $force) { |
111
|
|
|
$license = $this->askQuestion(new Question('License', $license)); |
112
|
|
|
$input->setOption('license', $license); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
// KEEKO values |
116
|
|
|
$output->writeln([ |
117
|
|
|
'', |
118
|
|
|
'Information for Keeko ' . ucfirst($type), |
119
|
|
|
'' |
120
|
|
|
]); |
121
|
|
|
|
122
|
|
|
// ask for the title |
123
|
|
|
$title = $this->getPackageTitle(); |
124
|
|
|
if ($title === null || $force) { |
125
|
|
|
$title = $this->askQuestion(new Question('Title', $title)); |
126
|
|
|
$input->setOption('title', $title); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
// ask for the class |
130
|
|
|
$classname = $this->getPackageClass(); |
131
|
|
|
if ($classname === null || $force) { |
132
|
|
|
$classname = $this->askQuestion(new Question('Class', $classname)); |
133
|
|
|
$input->setOption('classname', $classname); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
} |
This check marks private properties in classes that are never used. Those properties can be removed.