Skip to content

Commit 07222dd

Browse files
committed
Now it asks for configurations BEFORE installation starts
1 parent d52ca34 commit 07222dd

File tree

1 file changed

+41
-37
lines changed

1 file changed

+41
-37
lines changed

commands/NewCommand.php

+41-37
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ class NewCommand extends Command
2323

2424
protected static $defaultName = 'new';
2525

26+
protected static $availableContainers = [
27+
'Social Authentication' => 'apiato/social-auth-container',
28+
'Localization' => 'apiato/localization-container',
29+
'Payments' => 'apiato/payment-container',
30+
'Settings' => 'apiato/settings-container',
31+
];
32+
2633
protected function configure()
2734
{
2835
$this
@@ -38,6 +45,13 @@ protected function configure()
3845
protected function execute(InputInterface $input, OutputInterface $output)
3946
{
4047

48+
// Init
49+
$helper = $this->getHelper('question');
50+
$name = $input->getArgument('name');
51+
$directory = $name !== '.' ? getcwd() . '/' . $name : '.';
52+
$version = $this->getVersion($input);
53+
$composer = $this->findComposer();
54+
4155
$output->writeln([
4256
'<fg=red>' . PHP_EOL . PHP_EOL . PHP_EOL,
4357
" ___ .______ __ ___ .___________. ______ ",
@@ -51,11 +65,32 @@ protected function execute(InputInterface $input, OutputInterface $output)
5165

5266
sleep(1);
5367

54-
$name = $input->getArgument('name');
68+
// Ask for configurations
5569

56-
$directory = $name !== '.' ? getcwd() . '/' . $name : '.';
70+
$confirmation = new ConfirmationQuestion('Do you want to add additional containers? (yes/no) [no] ', false);
71+
$installContainersCommand = null;
5772

58-
$version = $this->getVersion($input);
73+
if ($helper->ask($input, $output, $confirmation)) {
74+
$question = new ChoiceQuestion(
75+
'Select all containers you want to install (example: 2,3,4).',
76+
array_keys(self::$availableContainers)
77+
);
78+
79+
$question->setMultiselect(true);
80+
81+
$selectedContainersArray = $helper->ask($input, $output, $question);
82+
$selectedContainersString = "";
83+
$installContainersCommand = ['cd ' . $directory];
84+
85+
foreach (array_keys(self::$availableContainers) as $availableContainer) {
86+
if (in_array($availableContainer, $selectedContainersArray)) {
87+
$selectedContainersString .= ' ' . self::$availableContainers[$availableContainer];
88+
}
89+
}
90+
array_push($installContainersCommand, $composer . " require" . $selectedContainersString);
91+
}
92+
93+
// Start installing project
5994

6095
if (!$input->getOption('force')) {
6196
$this->verifyApplicationDoesntExist($directory);
@@ -65,8 +100,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
65100
throw new RuntimeException('Cannot use --force option when using current directory for installation!');
66101
}
67102

68-
$composer = $this->findComposer();
69-
70103
$commands = [
71104
$composer . " create-project apiato/apiato \"$directory\" $version --remove-vcs --prefer-dist",
72105
];
@@ -91,39 +124,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
91124
}
92125
}
93126

94-
$helper = $this->getHelper('question');
95-
96-
$confirmation = new ConfirmationQuestion('Now do you want to add additional containers? [default: no] ', false);
97-
98-
$availableContainers = [
99-
'Social Authentication' => 'apiato/social-auth-container',
100-
'Localization' => 'apiato/localization-container',
101-
'Payments' => 'apiato/payment-container',
102-
'Settings' => 'apiato/settings-container',
103-
];
104-
105-
if ($helper->ask($input, $output, $confirmation)) {
106-
$question = new ChoiceQuestion(
107-
'Select all containers you want to install (example: 2,3,4).',
108-
array_keys($availableContainers)
109-
);
110-
111-
$question->setMultiselect(true);
112-
113-
$selectedContainersArray = $helper->ask($input, $output, $question);
114-
$selectedContainersString = "";
115-
$commands = ['cd ' . $directory];
116-
117-
foreach (array_keys($availableContainers) as $availableContainer) {
118-
if (in_array($availableContainer, $selectedContainersArray)) {
119-
$selectedContainersString .= ' ' . $availableContainers[$availableContainer];
120-
}
121-
}
122-
123-
array_push($commands, $composer . " require" . $selectedContainersString);
124-
$this->runCommands($commands, $input, $output);
125-
}
127+
// Install additional containers
128+
if ($installContainersCommand) $this->runCommands($installContainersCommand, $input, $output);
126129

130+
// The End
127131
$output->writeln(PHP_EOL . '<comment>Apiato ready! Build something amazing.</comment>');
128132

129133
return $process->getExitCode();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy