aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilly Micieli <micieli@laposte.net>2019-10-25 16:44:31 +0200
committerWilly Micieli <micieli@laposte.net>2019-10-25 16:44:31 +0200
commitfc04360d11adcf9fb28070a828d44ef84357134e (patch)
tree5e5143ea4d0ff9554c62c9754abf0ea4dddb2e90
parent77eddb67a0d0435cbe498ceffb2b6eab894f20c3 (diff)
downloadimperium-fc04360d11adcf9fb28070a828d44ef84357134e.zip
imperium-fc04360d11adcf9fb28070a828d44ef84357134e.tar.gz
add command to generate a new command
-rw-r--r--imperium/Command/Command.php2
-rw-r--r--imperium/Command/GenerateCommand.php53
2 files changed, 54 insertions, 1 deletions
diff --git a/imperium/Command/Command.php b/imperium/Command/Command.php
index 20bda27..abcd89b 100644
--- a/imperium/Command/Command.php
+++ b/imperium/Command/Command.php
@@ -46,7 +46,7 @@ namespace Imperium\Command {
public function run(): int
{
- $commands = [ new TodoMode(), new KeyGenerate(),new AdminMode(), new ImportDatabase(), new ProductionMode(), new Maintenance(), new GenerateMiddleware(), new GenerateView(), new GenerateRouteBase(), new GenerateModel(), new CleanDatabase(), new Dkim(), new DumpDatabase(), new GenerateController(), new GenerateMigrations(), new MigrateDatabase(), new RollbackDatabase(), new SeedDatabase(), new AddRoute(), new ListRoute(), new RemoveRoute(), new FindRoute(), new UpdateRoute(), new Serve()];
+ $commands = [ new GenerateCommand(), new TodoMode(), new KeyGenerate(),new AdminMode(), new ImportDatabase(), new ProductionMode(), new Maintenance(), new GenerateMiddleware(), new GenerateView(), new GenerateRouteBase(), new GenerateModel(), new CleanDatabase(), new Dkim(), new DumpDatabase(), new GenerateController(), new GenerateMigrations(), new MigrateDatabase(), new RollbackDatabase(), new SeedDatabase(), new AddRoute(), new ListRoute(), new RemoveRoute(), new FindRoute(), new UpdateRoute(), new Serve()];
$this->add($commands)->add(commands());
diff --git a/imperium/Command/GenerateCommand.php b/imperium/Command/GenerateCommand.php
new file mode 100644
index 0000000..6a2dccf
--- /dev/null
+++ b/imperium/Command/GenerateCommand.php
@@ -0,0 +1,53 @@
+<?php
+
+ namespace Imperium\Command;
+
+ use Imperium\Exception\Kedavra;
+ use Imperium\File\File;
+ use Symfony\Component\Console\Command\Command;
+ use Symfony\Component\Console\Input\InputArgument;
+ use Symfony\Component\Console\Input\InputInterface;
+ use Symfony\Component\Console\Output\OutputInterface;
+
+ class GenerateCommand extends Command
+ {
+
+ protected static $defaultName = "make:command";
+
+ protected function configure()
+ {
+
+ $this->setDescription('Generate a command')->addArgument('cmd', InputArgument::REQUIRED, 'the command name');
+ }
+
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ *
+ * @throws Kedavra
+ * @return int|void|null
+ */
+ public function execute(InputInterface $input, OutputInterface $output)
+ {
+
+ $command = ucfirst(strtolower(str_replace('Command','',$input->getArgument('cmd')))) .'Command';
+
+
+ $file = base('app') . DIRECTORY_SEPARATOR . 'Console' .DIRECTORY_SEPARATOR . $command. '.php';
+
+ if( ! file_exists($file))
+ {
+ if((new File($file, EMPTY_AND_WRITE_FILE_MODE))->write("<?php\n\n\t\tnamespace App\Console;\n\n\t\tuse Symfony\Component\Console\Command\Command;\n\t\tuse Symfony\Component\Console\Input\InputInterface;\n\t\tuse Symfony\Component\Console\Output\OutputInterface;\n\n\t\tclass {$command} extends Command\n\t\t{\n\n\t\t\tprotected static \$defaultName = '';\n\n\t\t\tprotected function configure()\n\t\t\t{\n\t\t\t\t\$this->setDescription('');\n\t\t\t}\n\n\t\t\tpublic function interact(InputInterface \$input, OutputInterface \$output)\n\t\t\t{\n\n\n\t\t\t}\n\n\t\t\tpublic function execute(InputInterface \$input, OutputInterface \$output)\n\t\t\t{\n\n\t\t\t\treturn 0;\n\t\t\t}\n\n\t\t}\n")->flush())
+ $output->writeln('<info>The command has been generated successfully</info>');
+
+ return 0;
+ }
+ else
+ {
+ $output->writeln('<bg=red;fg=white>The view already exist </>');
+
+ return 1;
+ }
+ }
+
+ } \ No newline at end of file