1313
1414use Github \Exception \ExceptionInterface ;
1515use Packagist \Api \Result \Package ;
16- use Symfony \Component \Console \Input \InputArgument ;
1716use Symfony \Component \Console \Input \InputInterface ;
18- use Symfony \Component \Console \Input \InputOption ;
1917use Symfony \Component \Console \Output \OutputInterface ;
18+ use Symfony \Component \Console \Question \Question ;
2019
2120/**
2221 * @author Jordi Sala <[email protected] > @@ -50,7 +49,10 @@ protected function configure()
5049
5150Usage:
5251
53- <info>php dev-kit release doctrine-orm-admin-bundle</info>
52+ <info>php dev-kit release</info>
53+
54+ First, a question about what bundle to release will be shown, this will be autocompleted will
55+ the projects configured on <info>projects.yml</info>
5456
5557The command will show what is the status of the project, then a list of pull requests
5658made against selected branch (default: stable branch) with the following information:
@@ -63,7 +65,6 @@ protected function configure()
6365 $ this
6466 ->setName ('release ' )
6567 ->setDescription ('Helps with a project release. ' )
66- ->addArgument ('project ' , InputArgument::REQUIRED , 'The project to release. ' )
6768 ->setHelp ($ help );
6869 }
6970
@@ -72,13 +73,7 @@ protected function configure()
7273 */
7374 protected function execute (InputInterface $ input , OutputInterface $ output )
7475 {
75- $ project = $ input ->getArgument ('project ' );
76-
77- if (!array_key_exists ($ project , $ this ->configs ['projects ' ])) {
78- $ this ->io ->error ('Project is not configured: ' .$ project );
79-
80- return 1 ;
81- }
76+ $ project = $ this ->getProject ($ input , $ output );
8277 $ branches = array_keys ($ this ->configs ['projects ' ][$ project ]['branches ' ]);
8378 $ branch = next ($ branches );
8479
@@ -93,6 +88,27 @@ protected function execute(InputInterface $input, OutputInterface $output)
9388 return 0 ;
9489 }
9590
91+ private function getProject (InputInterface $ input , OutputInterface $ output )
92+ {
93+ $ helper = $ this ->getHelper ('question ' );
94+
95+ $ question = new Question ('<info>Please enter the name of the project to release:</info> ' );
96+ $ question ->setAutocompleterValues (array_keys ($ this ->configs ['projects ' ]));
97+ $ question ->setNormalizer (function ($ answer ) {
98+ return $ answer ? trim ($ answer ) : '' ;
99+ });
100+ $ question ->setValidator (function ($ answer ) {
101+ if (!array_key_exists ($ answer , $ this ->configs ['projects ' ])) {
102+ throw new \RuntimeException ('The name of the project should be on projects.yml ' );
103+ }
104+
105+ return $ answer ;
106+ });
107+ $ question ->setMaxAttempts (3 );
108+
109+ return $ helper ->ask ($ input , $ output , $ question );
110+ }
111+
96112 private function prepareRelease (Package $ package , $ branch , OutputInterface $ output )
97113 {
98114 $ repositoryName = $ this ->getRepositoryName ($ package );
@@ -148,12 +164,12 @@ private function prepareRelease(Package $package, $branch, OutputInterface $outp
148164 $ this ->io ->warning ('Release is not needed ' );
149165 } else {
150166 $ this ->io ->success ('Next release will be: ' .$ nextVersion );
151- }
152167
153- $ this ->io ->section ('Changelog ' );
168+ $ this ->io ->section ('Changelog ' );
154169
155- $ this ->printRelease ($ currentRelease ['tag_name ' ], $ nextVersion , $ package , $ output );
156- $ this ->printChangelog ($ changelog , $ output );
170+ $ this ->printRelease ($ currentRelease ['tag_name ' ], $ nextVersion , $ package , $ output );
171+ $ this ->printChangelog ($ changelog , $ output );
172+ }
157173 }
158174
159175 private function printPullRequest ($ pull , OutputInterface $ output )
0 commit comments