|
13 | 13 |
|
14 | 14 | namespace Ymir\Cli\Command\Project; |
15 | 15 |
|
| 16 | +use Symfony\Component\Console\Exception\InvalidArgumentException; |
16 | 17 | use Symfony\Component\Console\Exception\RuntimeException; |
17 | 18 | use Symfony\Component\Console\Input\InputInterface; |
18 | 19 | use Symfony\Component\Console\Input\InputOption; |
@@ -70,7 +71,8 @@ protected function configure() |
70 | 71 | ->setName(self::NAME) |
71 | 72 | ->setAliases(['init']) |
72 | 73 | ->setDescription('Creates a new project in the current directory') |
73 | | - ->addOption('database', null, InputOption::VALUE_REQUIRED, 'The database used by the project'); |
| 74 | + ->addOption('database', null, InputOption::VALUE_REQUIRED, 'The database used by the project') |
| 75 | + ->addOption('name', null, InputOption::VALUE_REQUIRED, 'The name of the project'); |
74 | 76 | } |
75 | 77 |
|
76 | 78 | /** |
@@ -108,7 +110,7 @@ protected function perform(InputInterface $input, OutputStyle $output) |
108 | 110 | return; |
109 | 111 | } |
110 | 112 |
|
111 | | - $name = $output->askSlug('What is the name of the project'); |
| 113 | + $name = $this->determineName($input, $output); |
112 | 114 | $providerId = $this->determineCloudProvider($input, $output, 'Enter the ID of the cloud provider that the project will use'); |
113 | 115 | $region = $this->determineRegion($input, $output, $providerId, 'Enter the name of the region that the project will be in'); |
114 | 116 |
|
@@ -148,6 +150,22 @@ private function determineDatabaseName(OutputStyle $output): string |
148 | 150 | return $databaseName; |
149 | 151 | } |
150 | 152 |
|
| 153 | + /** |
| 154 | + * Determine the name of the project. |
| 155 | + */ |
| 156 | + private function determineName(InputInterface $input, OutputStyle $output): string |
| 157 | + { |
| 158 | + $name = $this->getStringOption($input, 'name'); |
| 159 | + |
| 160 | + if (empty($name) && !$input->isInteractive()) { |
| 161 | + throw new InvalidArgumentException('You must use the "--name" option when running in non-interactive mode'); |
| 162 | + } elseif (empty($name) && $input->isInteractive()) { |
| 163 | + $name = $output->askSlug('What is the name of the project'); |
| 164 | + } |
| 165 | + |
| 166 | + return (string) $name; |
| 167 | + } |
| 168 | + |
151 | 169 | /** |
152 | 170 | * Get the database name from the console input. |
153 | 171 | */ |
|
0 commit comments