1 | <?php |
||
2 | /** |
||
3 | * Copyright © Vaimo Group. All rights reserved. |
||
4 | * See LICENSE_VAIMO.txt for license details. |
||
5 | */ |
||
6 | namespace Vaimo\ComposerChangelogs\Commands; |
||
7 | |||
8 | use Symfony\Component\Console\Input\InputInterface; |
||
9 | use Symfony\Component\Console\Output\OutputInterface; |
||
10 | use Symfony\Component\Console\Input\InputArgument as Argument; |
||
11 | use Symfony\Component\Console\Input\InputOption as Option; |
||
12 | |||
13 | use Vaimo\ComposerChangelogs\Composer\Plugin\Config as PluginConfig; |
||
14 | use Vaimo\ComposerChangelogs\Composer\Config as ComposerConfig; |
||
15 | |||
16 | class BootstrapCommand extends \Composer\Command\BaseCommand |
||
17 | { |
||
18 | protected function configure() |
||
19 | { |
||
20 | $pluginConfig = new \Vaimo\ComposerChangelogs\Composer\Plugin\Config(); |
||
21 | |||
22 | $this->setName('changelog:bootstrap'); |
||
23 | |||
24 | $this->setDescription('Add basic configuration for the usage of generated change-logs'); |
||
25 | |||
26 | $this->addArgument( |
||
27 | 'name', |
||
28 | Argument::OPTIONAL, |
||
29 | 'Targeted package name. Default: root package' |
||
30 | ); |
||
31 | |||
32 | $this->addOption( |
||
33 | '--format', |
||
34 | null, |
||
35 | Option::VALUE_OPTIONAL, |
||
36 | sprintf('Format of the output (%s)', implode(', ', $pluginConfig->getAvailableFormats())), |
||
37 | 'md' |
||
38 | ); |
||
39 | } |
||
40 | |||
41 | protected function execute(InputInterface $input, OutputInterface $output) |
||
42 | { |
||
43 | $packageName = $input->getArgument('name'); |
||
44 | $format = $input->getOption('format'); |
||
45 | |||
46 | $composerCtxFactory = new \Vaimo\ComposerChangelogs\Factories\ComposerContextFactory($this->getComposer()); |
||
0 ignored issues
–
show
|
|||
47 | $composerCtx = $composerCtxFactory->create(); |
||
48 | |||
49 | $commandCtx = new \Vaimo\ComposerChangelogs\Console\Command\ExecutionContext($output, $composerCtx); |
||
50 | |||
51 | $cfgResolverFactory = new \Vaimo\ComposerChangelogs\Factories\Changelog\ConfigResolverFactory($composerCtx); |
||
52 | $cfgResolver = $cfgResolverFactory->create(); |
||
53 | |||
54 | $packageManager = new \Vaimo\ComposerChangelogs\Managers\PackageManager($composerCtx); |
||
55 | |||
56 | $package = $commandCtx->resolvePackage($packageName); |
||
57 | |||
58 | if ($package === null) { |
||
59 | return 1; |
||
60 | } |
||
61 | |||
62 | $output->writeln( |
||
63 | sprintf('Bootstrapping changelog generation for <info>%s</info>', $package->getName()) |
||
64 | ); |
||
65 | |||
66 | if ($cfgResolver->hasConfig($package)) { |
||
67 | $rootPath = array(ComposerConfig::CONFIG_ROOT, PluginConfig::ROOT); |
||
68 | |||
69 | $message = sprintf( |
||
70 | 'Configuration root (<comment>%s</comment>) already present in package config', |
||
71 | implode('/', $rootPath) |
||
72 | ); |
||
73 | |||
74 | $output->writeln($message); |
||
75 | |||
76 | return 0; |
||
77 | } |
||
78 | |||
79 | try { |
||
80 | $packageManager->bootstrapChangelogGeneration($package, $format); |
||
81 | } catch (\Vaimo\ComposerChangelogs\Exceptions\UpdaterException $exception) { |
||
82 | $message = sprintf('<error>%s</error>', $exception->getMessage()); |
||
83 | $output->writeln($message); |
||
84 | |||
85 | return 1; |
||
86 | } |
||
87 | |||
88 | $output->writeln('<info>Done</info>'); |
||
89 | |||
90 | return 0; |
||
91 | } |
||
92 | } |
||
93 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.