Skip to content

Commit

Permalink
Merge pull request #32 from gacela-project/feature/change-default-lon…
Browse files Browse the repository at this point in the history
…g-name-command-generator

Using long name by default in the generator code commands
  • Loading branch information
Chemaclass authored Jul 4, 2021
2 parents 49c262a + 2c40679 commit ae92905
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/CodeGenerator/Domain/FileContentGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public function __construct(CodeTemplateInterface $codeTemplate)
/**
* @return string path result where the file was generated
*/
public function generate(CommandArguments $commandArguments, string $filename, bool $withLongName): string
public function generate(CommandArguments $commandArguments, string $filename, bool $withShortName): string
{
$this->mkdir($commandArguments->directory());

$moduleName = $withLongName ? $commandArguments->basename() : '';
$moduleName = $withShortName ? '' : $commandArguments->basename();
$className = $moduleName . $filename;

$path = sprintf('%s/%s.php', $commandArguments->directory(), $className);
Expand Down
7 changes: 4 additions & 3 deletions src/CodeGenerator/Infrastructure/Command/MakeFileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function configure(): void
$this->setDescription('Generate a ' . FilenameSanitizer::expectedFilenames())
->addArgument('path', InputArgument::REQUIRED, 'The file path. For example "App/TestModule/TestSubModule"')
->addArgument('filenames', InputArgument::REQUIRED | InputArgument::IS_ARRAY, FilenameSanitizer::expectedFilenames(' | '))
->addOption('long-name', 'l', InputOption::VALUE_NONE, 'Add module as prefix to the class name');
->addOption('short-name', 's', InputOption::VALUE_NONE, 'Remove module prefix to the class name');
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand All @@ -48,16 +48,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
/** @var string $path */
$path = $input->getArgument('path');
$commandArguments = $this->argumentsParser->parse($path);
$shortName = (bool)$input->getOption('short-name');

foreach ($filenames as $filename) {
$fullPath = $this->fileContentGenerator->generate(
$commandArguments,
$filename,
(bool)$input->getOption('long-name')
$shortName
);
$output->writeln("> Path '$fullPath' created successfully");
}

return 0;
return self::SUCCESS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,21 @@ protected function configure(): void
{
$this->setDescription('Generate a basic module with an empty ' . FilenameSanitizer::expectedFilenames())
->addArgument('path', InputArgument::REQUIRED, 'The file path. For example "App/TestModule/TestSubModule"')
->addOption('long-name', 'l', InputOption::VALUE_NONE, 'Add module as prefix to the class name');
->addOption('short-name', 's', InputOption::VALUE_NONE, 'Remove module prefix to the class name');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
/** @var string $path */
$path = $input->getArgument('path');
$commandArguments = $this->argumentsParser->parse($path);
$shortName = (bool)$input->getOption('short-name');

foreach (FilenameSanitizer::EXPECTED_FILENAMES as $filename) {
$fullPath = $this->fileContentGenerator->generate(
$commandArguments,
$filename,
(bool)$input->getOption('long-name')
$shortName
);
$output->writeln("> Path '$fullPath' created successfully");
}
Expand All @@ -53,6 +54,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$moduleName = end($pieces);
$output->writeln("Module '$moduleName' created successfully");

return 0;
return self::SUCCESS;
}
}

0 comments on commit ae92905

Please sign in to comment.