Skip to content

Commit 3eb71b9

Browse files
committed
feat: added name option for project:init command
1 parent 017ea1e commit 3eb71b9

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/Command/Project/InitializeProjectCommand.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Ymir\Cli\Command\Project;
1515

16+
use Symfony\Component\Console\Exception\InvalidArgumentException;
1617
use Symfony\Component\Console\Exception\RuntimeException;
1718
use Symfony\Component\Console\Input\InputInterface;
1819
use Symfony\Component\Console\Input\InputOption;
@@ -70,7 +71,8 @@ protected function configure()
7071
->setName(self::NAME)
7172
->setAliases(['init'])
7273
->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');
7476
}
7577

7678
/**
@@ -108,7 +110,7 @@ protected function perform(InputInterface $input, OutputStyle $output)
108110
return;
109111
}
110112

111-
$name = $output->askSlug('What is the name of the project');
113+
$name = $this->determineName($input, $output);
112114
$providerId = $this->determineCloudProvider($input, $output, 'Enter the ID of the cloud provider that the project will use');
113115
$region = $this->determineRegion($input, $output, $providerId, 'Enter the name of the region that the project will be in');
114116

@@ -148,6 +150,22 @@ private function determineDatabaseName(OutputStyle $output): string
148150
return $databaseName;
149151
}
150152

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+
151169
/**
152170
* Get the database name from the console input.
153171
*/

0 commit comments

Comments
 (0)