From 482beb7010351f5bc438cf90d038cc8bd6165267 Mon Sep 17 00:00:00 2001 From: magdev Date: Wed, 5 Jun 2019 09:35:13 +0200 Subject: [PATCH] Reorganized commands, removed theme-commands and edit-commands --- .../CreateCvCommand.php} | 13 +- .../CreateIntroCommand.php} | 10 +- .../CreatePersonCommand.php} | 10 +- src/Command/Create/CreateProjectCommand.php | 129 ++++++++++++++++++ src/Command/Cv/CvEditCommand.php | 70 ---------- src/Command/Intro/IntroEditCommand.php | 69 ---------- src/Command/Person/PersonEditCommand.php | 69 ---------- src/Command/Theme/ThemeDumpCommand.php | 108 --------------- src/Command/Theme/ThemeListCommand.php | 72 ---------- 9 files changed, 152 insertions(+), 398 deletions(-) rename src/Command/{Cv/CvAddCommand.php => Create/CreateCvCommand.php} (92%) rename src/Command/{Intro/IntroAddCommand.php => Create/CreateIntroCommand.php} (93%) rename src/Command/{Person/PersonAddCommand.php => Create/CreatePersonCommand.php} (93%) create mode 100644 src/Command/Create/CreateProjectCommand.php delete mode 100644 src/Command/Cv/CvEditCommand.php delete mode 100644 src/Command/Intro/IntroEditCommand.php delete mode 100644 src/Command/Person/PersonEditCommand.php delete mode 100644 src/Command/Theme/ThemeDumpCommand.php delete mode 100644 src/Command/Theme/ThemeListCommand.php diff --git a/src/Command/Cv/CvAddCommand.php b/src/Command/Create/CreateCvCommand.php similarity index 92% rename from src/Command/Cv/CvAddCommand.php rename to src/Command/Create/CreateCvCommand.php index 24d70b1..aa65f65 100644 --- a/src/Command/Cv/CvAddCommand.php +++ b/src/Command/Create/CreateCvCommand.php @@ -28,7 +28,7 @@ * @license http://opensource.org/licenses/MIT MIT License */ -namespace Magdev\Dossier\Command\Cv; +namespace Magdev\Dossier\Command\Create; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; @@ -43,7 +43,7 @@ use Magdev\Dossier\Command\Base\BaseCommand; * * @author magdev */ -final class CvAddCommand extends BaseCommand +final class CreateCvCommand extends BaseCommand { /** * TheCV Form @@ -58,7 +58,7 @@ final class CvAddCommand extends BaseCommand */ protected function configure() { - $this->setName('cv:add') + $this->setName('create:cv') ->setDescription('Write a new CV entry') ->addArgument('name', InputArgument::REQUIRED, 'Choose the name of the entry') ->addOption('review', 'r', InputOption::VALUE_NONE, 'Review file in editor'); @@ -72,7 +72,12 @@ final class CvAddCommand extends BaseCommand * @see \Magdev\Dossier\Command\BaseCommand::initialize() */ protected function initialize(InputInterface $input, OutputInterface $output) - { + { + $name = $input->getArgument('name'); + if (file_exists(PROJECT_ROOT.'/cv/'.$name.'.md')) { + throw new \RuntimeException('File cv/'.$name.'.md already exists'); + } + try { $this->form = $this->getHelper('form')->getFormByName('form.cv', $input, $output); parent::initialize($input, $output); diff --git a/src/Command/Intro/IntroAddCommand.php b/src/Command/Create/CreateIntroCommand.php similarity index 93% rename from src/Command/Intro/IntroAddCommand.php rename to src/Command/Create/CreateIntroCommand.php index ae6aeed..3d1703a 100644 --- a/src/Command/Intro/IntroAddCommand.php +++ b/src/Command/Create/CreateIntroCommand.php @@ -28,7 +28,7 @@ * @license http://opensource.org/licenses/MIT MIT License */ -namespace Magdev\Dossier\Command\Intro; +namespace Magdev\Dossier\Command\Create; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -37,7 +37,7 @@ use Symfony\Component\Console\Exception\RuntimeException; use Droath\ConsoleForm\Exception\FormException; use Magdev\Dossier\Command\Base\BaseCommand; -final class IntroAddCommand extends BaseCommand +final class CreateIntroCommand extends BaseCommand { /** * The IntroForm @@ -52,7 +52,7 @@ final class IntroAddCommand extends BaseCommand */ protected function configure() { - $this->setName('intro:add') + $this->setName('create:intro') ->setDescription('Write the Intro page') ->addOption('review', 'r', InputOption::VALUE_NONE, 'Review file in editor'); @@ -68,6 +68,10 @@ final class IntroAddCommand extends BaseCommand { parent::initialize($input, $output); + if (file_exists(PROJECT_ROOT.'/intro.md')) { + throw new \RuntimeException('File intro.md already exists'); + } + try { $this->form = $this->getHelper('form') ->getFormByName('form.intro', $input, $output); diff --git a/src/Command/Person/PersonAddCommand.php b/src/Command/Create/CreatePersonCommand.php similarity index 93% rename from src/Command/Person/PersonAddCommand.php rename to src/Command/Create/CreatePersonCommand.php index 22f5c01..9d506bf 100644 --- a/src/Command/Person/PersonAddCommand.php +++ b/src/Command/Create/CreatePersonCommand.php @@ -28,7 +28,7 @@ * @license http://opensource.org/licenses/MIT MIT License */ -namespace Magdev\Dossier\Command\Person; +namespace Magdev\Dossier\Command\Create; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -37,7 +37,7 @@ use Symfony\Component\Console\Exception\RuntimeException; use Droath\ConsoleForm\Exception\FormException; use Magdev\Dossier\Command\Base\BaseCommand; -final class PersonAddCommand extends BaseCommand +final class CreatePersonCommand extends BaseCommand { /** * The IntroForm @@ -52,7 +52,7 @@ final class PersonAddCommand extends BaseCommand */ protected function configure() { - $this->setName('person:add') + $this->setName('create:person') ->setDescription('Write the Person page') ->addOption('review', 'r', InputOption::VALUE_NONE, 'Review file in editor'); @@ -68,6 +68,10 @@ final class PersonAddCommand extends BaseCommand { parent::initialize($input, $output); + if (file_exists(PROJECT_ROOT.'/person.md')) { + throw new \RuntimeException('File person.md already exists'); + } + try { $this->form = $this->getHelper('form') ->getFormByName('form.person', $input, $output); diff --git a/src/Command/Create/CreateProjectCommand.php b/src/Command/Create/CreateProjectCommand.php new file mode 100644 index 0000000..e7aeea7 --- /dev/null +++ b/src/Command/Create/CreateProjectCommand.php @@ -0,0 +1,129 @@ +setName('create:project') + ->setDescription('Write a new project file') + ->addArgument('name', InputArgument::REQUIRED, 'Choose the name of the entry') + ->addOption('review', 'r', InputOption::VALUE_NONE, 'Review file in editor'); + + parent::configure(); + } + + + /** + * {@inheritDoc} + * @see \Magdev\Dossier\Command\BaseCommand::initialize() + */ + protected function initialize(InputInterface $input, OutputInterface $output) + { + $name = $input->getArgument('name'); + if (file_exists(PROJECT_ROOT.'/projects/'.$name.'.md')) { + throw new \RuntimeException('File projects/'.$name.'.md already exists'); + } + + try { + $this->form = $this->getHelper('form')->getFormByName('form.project', $input, $output); + parent::initialize($input, $output); + } catch (FormException $fe) { + throw new RuntimeException(get_class($fe).': '.$fe->getMessage(), $fe->getCode(), $fe); + } + } + + /** + * {@inheritDoc} + * @see \Symfony\Component\Console\Command\Command::interact() + */ + protected function interact(InputInterface $input, OutputInterface $output) + { + $this->io->title($this->translator->trans('form.project.header.add')); + $this->io->newLine(); + $this->form->process(); + } + + + /** + * {@inheritDoc} + * @see \Symfony\Component\Console\Command\Command::execute() + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + if ($this->form->isProcessed()) { + $markdown = $this->getService('markdown'); + /* @var $markdown \Magdev\Dossier\Service\MarkdownService */ + + try { + $text = $this->form->stripData('text', ''); + $name = $input->getArgument('name'); + + $markdown->save(PROJECT_ROOT.'/projects/'.$name.'.md', $this->form->getResults(), $text, false); + $this->io->success($this->translator->trans('message.write.success', array( + '%name%' => 'Project/'.ucfirst($name) + ))); + + if ($input->getOption('review') != false) { + $this->getService('uri_helper')->openFileInEditor(PROJECT_ROOT.'/projects/'.$name.'.md'); + } + } catch (FormException $fe) { + throw new RuntimeException(get_class($fe).': '.$fe->getMessage(), $fe->getCode(), $fe); + } + } + } +} + diff --git a/src/Command/Cv/CvEditCommand.php b/src/Command/Cv/CvEditCommand.php deleted file mode 100644 index d65345a..0000000 --- a/src/Command/Cv/CvEditCommand.php +++ /dev/null @@ -1,70 +0,0 @@ -setName('cv:edit') - ->setDescription('Edit a CV entry in your default editor') - ->addArgument('file', InputArgument::REQUIRED, 'Filename of the entry w/o extension'); - - parent::configure(); - } - - - /** - * {@inheritDoc} - * @see \Symfony\Component\Console\Command\Command::configure() - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $file = PROJECT_ROOT.'/cv/'.$input->getArgument('file').'.md'; - - if (!file_exists($file)) { - throw new RuntimeException('File '.$file.' not found'); - } - - $this->getService('uri_helper')->openFileInEditor($file); - } -} - diff --git a/src/Command/Intro/IntroEditCommand.php b/src/Command/Intro/IntroEditCommand.php deleted file mode 100644 index 510610c..0000000 --- a/src/Command/Intro/IntroEditCommand.php +++ /dev/null @@ -1,69 +0,0 @@ -setName('intro:edit') - ->setDescription('Edit the intro in your default editor'); - - parent::configure(); - } - - - /** - * {@inheritDoc} - * @see \Symfony\Component\Console\Command\Command::configure() - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $file = PROJECT_ROOT.'/intro.md'; - - if (!file_exists($file)) { - throw new RuntimeException('File '.$file.' not found'); - } - - $this->getService('uri_helper')->openFileInEditor($file); - } -} - diff --git a/src/Command/Person/PersonEditCommand.php b/src/Command/Person/PersonEditCommand.php deleted file mode 100644 index f7e9c86..0000000 --- a/src/Command/Person/PersonEditCommand.php +++ /dev/null @@ -1,69 +0,0 @@ -setName('person:edit') - ->setDescription('Edit personal data in your default editor'); - - parent::configure(); - } - - - /** - * {@inheritDoc} - * @see \Symfony\Component\Console\Command\Command::configure() - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $file = PROJECT_ROOT.'/person.md'; - - if (!file_exists($file)) { - throw new RuntimeException('File '.$file.' not found'); - } - - $this->getService('uri_helper')->openFileInEditor($file); - } -} - diff --git a/src/Command/Theme/ThemeDumpCommand.php b/src/Command/Theme/ThemeDumpCommand.php deleted file mode 100644 index 2be1536..0000000 --- a/src/Command/Theme/ThemeDumpCommand.php +++ /dev/null @@ -1,108 +0,0 @@ -setName('theme:dump') - ->setDescription('Create a local copy of a theme') - - ->addArgument('theme', InputArgument::REQUIRED, 'The name of the theme') - ->addOption('locale', 'l', InputOption::VALUE_OPTIONAL, 'Set the locale', 'de') - ->addOption('rename', 'r', InputOption::VALUE_OPTIONAL, 'Rename the theme', '') - ->addOption('output', 'o', InputOption::VALUE_OPTIONAL, 'Output folder', getenv('HOME').'/.dossier/tpl'); - - parent::configure(); - } - - - /** - * {@inheritDoc} - * @see \Symfony\Component\Console\Command\Command::initialize() - */ - protected function initialize(InputInterface $input, OutputInterface $output) - { - $this->pharHelper = $this->getService('phar_helper'); - - parent::initialize($input, $output); - } - - - /** - * {@inheritDoc} - * @see \Symfony\Component\Console\Command\Command::execute() - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $theme = $input->getArgument('theme'); - $outDir = $input->getOption('output'); - $newName = $input->getOption('rename'); - - $themeDir = 'app/tpl/'.$theme; - $targetDir = !$newName ? $outDir.'/'.$theme : $outDir.'/'.$newName; - $this->pharHelper->copyDir($themeDir, $targetDir); - - $this->io->success($this->translator->trans('message.dump.success', array('%theme%' => $theme))); - /* - if ($outDir != getenv('HOME').'/.dossier/tpl') { - $output->writeln(' '.$this->translator->trans('message.export.template_dir').''); - $output->writeln(' '.$this->translator->trans('message.export.code.template_environment', array('%path%' => $outDir)).''); - } else { - $output->writeln(' '.$this->translator->trans('message.export.template_homedir').''); - }*/ - $this->io->newLine(); - } -} - diff --git a/src/Command/Theme/ThemeListCommand.php b/src/Command/Theme/ThemeListCommand.php deleted file mode 100644 index a852b90..0000000 --- a/src/Command/Theme/ThemeListCommand.php +++ /dev/null @@ -1,72 +0,0 @@ -setName('theme:list') - ->setDescription('List available themes') - ->addOption('all', 'a', InputOption::VALUE_NONE, 'List all themes, icluding the overridden ones'); - - parent::configure(); - } - - - /** - * {@inheritDoc} - * @see \Symfony\Component\Console\Command\Command::execute() - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $all = (bool) $input->getOption('all'); - $helper = $this->getHelper('export'); - /* @var $helper \Magdev\Dossier\Helper\ExportHelper */ - - $themes = $this->config->findThemes($all); - } -} -