Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify options on CreateCommand #223

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/Command/CreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ protected function configure(): void
{
$this
->addArgument('name', InputArgument::REQUIRED, 'Table name to generate migration for.')
->addOption('command', 'c', InputOption::VALUE_OPTIONAL, 'Command to execute.', 'create')
->addOption('fields', 'f', InputOption::VALUE_OPTIONAL, 'Table fields to generate.')
->addOption('table-comment', null, InputOption::VALUE_OPTIONAL, 'Table comment.')
->addOption('and', null, InputOption::VALUE_OPTIONAL, 'And junction.')
->addOption('command', 'c', InputOption::VALUE_REQUIRED, 'Command to execute.', 'create')
->addOption('fields', 'f', InputOption::VALUE_REQUIRED, 'Table fields to generate.')
->addOption('table-comment', null, InputOption::VALUE_REQUIRED, 'Table comment.')
->addOption('and', null, InputOption::VALUE_REQUIRED, 'And junction.')
Comment on lines +81 to +84
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these really required?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means if you call the command with an option you should specify a value.

It makes no sense to call the command with these options without values.

e.g. ./yii migrate:create post --command

->addOption('path', null, InputOption::VALUE_REQUIRED, 'Path to migration directory.')
->addOption('namespace', 'ns', InputOption::VALUE_REQUIRED, 'Migration file namespace.')
->setHelp('This command generates new migration file.');
Expand Down Expand Up @@ -131,7 +131,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return Command::INVALID;
}

/** @var string $and */
/** @var string|null $and */
$and = $input->getOption('and');
$name = $this->generateName($command, $table, $and);

Expand Down Expand Up @@ -166,8 +166,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
);

if ($helper->ask($input, $output, $question)) {
$fields = $input->hasOption('fields') ? (string) $input->getOption('fields') : null;
$tableComment = $input->hasOption('table-comment') ? (string) $input->getOption('table-comment') : null;
/** @var string|null $fields */
$fields = $input->getOption('fields');
/** @var string|null $tableComment */
$tableComment = $input->getOption('table-comment');

$content = $this->createService->run(
$command,
Expand Down
Loading