Skip to content

Commit f1e9503

Browse files
committed
add interactive menu
1 parent fa6f1a6 commit f1e9503

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

src/Maker/MakeScaffold.php

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,47 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma
100100
return;
101101
}
102102

103-
$availableScaffolds = array_combine(
104-
array_keys($this->availableScaffolds()),
105-
array_map(fn (array $scaffold) => $scaffold['description'], $this->availableScaffolds())
106-
);
103+
$scaffolds = $this->availableScaffolds();
104+
105+
while (true) {
106+
$name = $io->choice('Available scaffolds', array_combine(
107+
array_keys($scaffolds),
108+
array_map(fn (array $scaffold) => $scaffold['description'], $scaffolds)
109+
));
110+
$scaffold = $scaffolds[$name];
111+
112+
$io->title($name);
113+
$io->text($scaffold['description']);
114+
$io->newLine();
115+
116+
if ($scaffold['dependents'] ?? []) {
117+
$io->text('This scaffold will also install the following scaffolds:');
118+
$io->newLine();
119+
$io->listing(\array_map(fn($s) => \sprintf('%s - %s', $s, $scaffolds[$s]['description']), $scaffold['dependents']));
120+
}
121+
122+
if ($scaffold['packages'] ?? []) {
123+
$io->text('This scaffold will install the following composer packages:');
124+
$io->newLine();
125+
$io->listing(\array_keys($scaffold['packages']));
126+
}
127+
128+
if ($scaffold['js_packages'] ?? []) {
129+
$io->text('This scaffold will install the following node packages:');
130+
$io->newLine();
131+
$io->listing(\array_keys($scaffold['js_packages']));
132+
}
133+
134+
if (!$io->confirm("Would your like to create the \"{$name}\" scaffold?")) {
135+
$io->text('Going back to main menu...');
107136

108-
$input->setArgument('name', [$io->choice('Available scaffolds', $availableScaffolds)]);
137+
continue;
138+
}
139+
140+
$input->setArgument('name', [$name]);
141+
142+
return;
143+
}
109144
}
110145

111146
private function generateScaffold(string $name, ConsoleStyle $io): void

0 commit comments

Comments
 (0)