protected function execute(InputInterface $input, OutputInterface $output)
 {
     Wp::load();
     $targetTheme = null;
     $targetThemeSlug = $input->getArgument('theme');
     if (static::CURRENT_THEME == $input->getArgument('theme')) {
         // no user chosen theme: load current
         /** @var \WP_Theme $targetTheme */
         $targetTheme = wp_get_theme();
         $targetThemeSlug = $targetTheme->get_stylesheet();
     }
     if (!$targetTheme) {
         // load user chosen theme
         $targetTheme = wp_get_theme($targetThemeSlug);
     }
     if (!$targetTheme->exists()) {
         throw new \DomainException('Theme ' . $targetThemeSlug . ' does not exist.');
     }
     if ($output->isDebug()) {
         $output->writeln('Theme: ' . $targetTheme->get_stylesheet());
     }
     $morphMethod = $this->getMorphMethod($input);
     // resolve readable name
     $name = $targetThemeSlug;
     if ($targetTheme->get('Name')) {
         $name = $targetTheme->get('Name');
     }
     $this->verbose('Checking ' . $name);
     // resolve theme text domain
     $textDomain = $name;
     if ($targetTheme->get('TextDomain')) {
         $textDomain = $targetTheme->get('TextDomain');
     }
     $this->verbose(' (TextDomain: ' . $textDomain . ')' . PHP_EOL);
     $langPath = WpTheme::resolveLanguagesPath($targetTheme);
     // fetch strings
     $extractor = new WordPressExtractor();
     $extractor::$extractComments = true;
     $extractor::$textDomain = $textDomain;
     $translatable = $extractor->fromDirectory($targetTheme->get_stylesheet_directory());
     // todo B fetch and merge translations from po file
     $translatable->setDomain($textDomain);
     $translatable->ksort();
     // skeleton created
     // file name is same as the slug which is a common way if you look at twenty* themes.
     $skeletonBasename = $targetThemeSlug . '.' . $input->getOption('format');
     if ('po' == $input->getOption('format')) {
         // po templates have the pot extension in the filename
         $skeletonBasename .= 't';
     }
     // merge with existing template
     $skeletonPath = $langPath . '/' . $skeletonBasename;
     $extractMethod = 'from' . ucfirst($input->getOption('format')) . 'File';
     /** @var Translations $skeletonTranslation */
     $skeletonTranslation = call_user_func(['\\Gettext\\Translations', $extractMethod], [$skeletonPath]);
     $this->sanitizeTranslation($translatable, $textDomain, $targetTheme->get_stylesheet_directory());
     $skeletonTranslation->mergeWith($translatable, $translatable::MERGE_ADD | $translatable::MERGE_REFERENCES);
     $this->writeTranslation($input, $output, $skeletonPath, $skeletonTranslation);
     $this->updateTranslations($input, $output, $targetTheme, $skeletonTranslation, $textDomain);
 }
 /**
  * @param $targetPluginSlug
  * @return mixed
  */
 protected function resolvePluginDir($targetPluginSlug)
 {
     $plugins = Wp::getPlugins();
     if (!array_key_exists($targetPluginSlug, $plugins)) {
         throw new \DomainException('Plugin ' . $targetPluginSlug . ' does not exist.');
     }
     $targetPluginDir = $plugins[$targetPluginSlug];
     return $targetPluginDir;
 }