45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Spark\Commands;
|
|
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
|
use Spark\Commands\Command;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
#[AsCommand(name:'init', description:'Initialize a new spark in the current directory')]
|
|
class InitCommand extends Command
|
|
{
|
|
protected function configure()
|
|
{
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
{
|
|
$configDir = getcwd()."/.spark";
|
|
if (is_dir($configDir)) {
|
|
$output->writeln("<notice>Spark already initialized?</>");
|
|
return Command::FAILURE;
|
|
}
|
|
|
|
mkdir($configDir);
|
|
mkdir($configDir."/plugins");
|
|
mkdir($configDir."/scripts");
|
|
file_put_contents($configDir."/spark.json", json_encode([
|
|
'preload' => [
|
|
'./.spark/plugins/*',
|
|
'./.spark/scripts/*'
|
|
],
|
|
'scripts' => [
|
|
'hello' => "echo 'Hello World'"
|
|
]
|
|
], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
|
|
|
|
$output->writeln("<fg=green>Initialized new spark in ".getcwd()."/.spark</>");
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|