protected function execute(InputInterface $input, OutputInterface $output)
 {
     $component = new BitrixComponent($input->getArgument('name'));
     if ($component->exists()) {
         $output->writeln("<error>Component {$componentName} already exists!</error>");
         $output->writeln("<info>" . $component->getComponentDir() . "</info>");
         return 1;
     }
     $namespace = $component->getNamespace();
     $componentName = $component->getName();
     $siteRoot = BitrixTool::getInstance()->getSiteRoot();
     if (!$siteRoot) {
         $output->writeln("<error>Not in a Bitrix web root!</error>");
         return 1;
     }
     $bitrixFolder = $input->getOption('bitrix') ? 'btrix' : 'local';
     $componentFolder = "{$siteRoot}/{$bitrixFolder}/components/{$namespace}/{$componentName}";
     $componentTemplateFolder = "{$componentFolder}/template/.default";
     $componentFiles = array('description' => "{$componentFolder}/.description.php", 'parameters' => "{$componentFolder}/.parameters.php", 'component' => "{$componentFolder}/component.php", 'template' => "{$componentTemplateFolder}/template.php");
     // Создаем структуру каталогов.
     if (!file_exists($componentTemplateFolder) && !$this->createFolder($componentTemplateFolder)) {
         return 1;
     }
     file_put_contents($componentFiles['component'], COMPONENT_TEMPLATE_COMPONENT);
     file_put_contents($componentFiles['parameters'], COMPONENT_TEMPLATE_PARAMETERS);
     file_put_contents($componentFiles['description'], COMPONENT_TEMPLATE_DESCRIPTION);
     file_put_contents($componentFiles['template'], COMPONENT_TEMPLATE_TEMPLATE);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $componentName = $input->getArgument('component');
     $component = new BitrixComponent($componentName);
     if (!$component->exists()) {
         $output->writeln("<error>Component {$componentName} not found </error>");
         return 1;
     }
     $showFullPath = $input->getOption('full-path');
     $showLocation = $input->getOption('show-location');
     if ($input->getOption('default')) {
         $templates = $component->getDefaultTemplates($showFullPath);
     } else {
         if ($input->getOption('bitrix')) {
             $templates = $component->getSiteTemplates('bitrix', $showFullPath, $showLocation);
         } else {
             if ($input->getOption('local')) {
                 $templates = $component->getSiteTemplates('local', $showFullPath, $showLocation);
             } else {
                 $templates = array_merge($component->getDefaultTemplates($showFullPath), $component->getSiteTemplates('bitrix', $showFullPath, $showLocation), $component->getSiteTemplates('local', $showFullPath, $showLocation));
             }
         }
     }
     foreach ($templates as $template) {
         $output->writeln("<info>{$template}</info>");
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $bitrix = BitrixTool::getInstance();
     // Исходный компонент.
     $componentName = $input->getOption('component');
     $component = new BitrixComponent($componentName);
     if (!$component->exists()) {
         $output->writeln("<error>Component {$componentName} not found </error>");
         return 1;
     }
     // Копируемый шаблон.
     $srcTemplateName = $input->getArgument('source');
     $srcTemplatePath = $component->getTemplatePath($srcTemplateName);
     if (!file_exists($srcTemplatePath)) {
         $output->writeln("<error>Template {$srcTemplatePath} not found for component {$componentName}</error>");
         return 1;
     }
     // Шаблон сайта, в который будет скопирован шаблон.
     $siteTemplateName = $input->getOption('site-template');
     if (!$siteTemplateName) {
         $output->writeln("<error>Site template name not specified!</error>");
         $output->writeln("<comment>Use --site-template option to specify site template where " . "to place component template.</comment>");
         return 1;
     }
     if (!$bitrix->siteTemplateExists($siteTemplateName)) {
         $output->writeln("<error>Site template {$siteTemplateName} does not exist</error>");
         return 1;
     }
     // Название с которым будет скопирован шаблон.
     $dstTemplateName = $input->getArgument('destination');
     if (!$dstTemplateName) {
         $dstTemplateName = $srcTemplateName;
     }
     // Путь к целевому шаблону.
     $dstTemplatePath = $component->getLocalTemplatePath($siteTemplateName, $dstTemplateName);
     if (file_exists($dstTemplatePath) && !$input->getOption('force')) {
         $output->writeln("<error>Template {$dstTemplateName} already exsist.</error>");
         $output->writeln("<info>Use --force option to overwrite</info>");
         return 1;
     }
     $output->writeln("<comment>Copying component template:</comment>");
     $output->writeln("<comment>--> from:</comment> <info>{$srcTemplatePath}</info>");
     $output->writeln("<comment>--> to:</comment> <info>{$dstTemplatePath}</info>");
     FileSystemHelpers::CopyDir($srcTemplatePath, $dstTemplatePath);
     $output->writeln('<comment>Done!</comment>');
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $componentName = $input->getOption('component');
     if (!$componentName) {
         $output->writeln('<error>Component name must be given</error>');
         $output->writeln('<comment>Use -c option to specify component name</comment>');
         return 1;
         // set error status code
     }
     $component = new BitrixComponent($componentName);
     if (!$component->exists()) {
         $output->writeln("<error>Component {$componentName} not found </error>");
         return 1;
     }
     $templateName = $input->getArgument('template');
     if (!$templateName) {
         $templateName = '';
     }
     $buff = new BufferedOutput();
     $buff->writeln(sprintf('<?$APPLICATION->IncludeComponent("%s", "%s", array(', $component->getFullName(), $templateName));
     $parameters = $component->getParameters()['PARAMETERS'];
     if ($input->getOption('sort')) {
         ksort($parameters);
     }
     foreach ($parameters as $name => $settings) {
         // TODO: Добавить вывод комментария с именем параметра.
         $defaultValue = $settings['DEFAULT'] ? $settings['DEFAULT'] : '';
         $buff->writeln(sprintf('    "%s" => %s,', $name, var_export($defaultValue, true)));
     }
     $buff->writeln('  ),');
     $buff->writeln('  false');
     $buff->writeln(');/*' . $componentName . "*/?>");
     $code = $buff->fetch();
     if ($input->getOption('xclip')) {
         $clip = new ClipboardStream();
         $clip->write($code);
         $output->writeln('<comment>Generated code was copied to clipboard</comment>');
     } else {
         $output->write("<info>{$code}</info>");
     }
 }