11<?php
22
3+ declare (strict_types=1 );
4+
35namespace Artemeon \M2G \Command ;
46
57use Artemeon \M2G \Config \ConfigReader ;
6- use Symfony \Component \Console \Input \InputArgument ;
78use Symfony \Component \Yaml \Yaml ;
89
910use function Termwind \{render , terminal };
1011
1112class ConfigurationCommand extends Command
1213{
14+ protected string $ signature = 'configure {file? : The config.yaml to use for setting up the tool.} ' ;
15+ protected ?string $ description = 'Configure the tool ' ;
16+
1317 protected string $ configPath = __DIR__ . '/../../../config.yaml ' ;
1418 protected array $ config = [];
1519
16- protected function configure ()
17- {
18- $ this ->setName ('configure ' )
19- ->setDescription ('Configure the tool ' )
20- ->addArgument ('file ' , InputArgument::OPTIONAL , 'The config.yaml to use for setting up the tool. ' );
21- }
22-
23- protected function handle (): int
20+ public function __invoke (): int
2421 {
2522 $ this ->readExistingConfigFromPath ();
2623
@@ -34,9 +31,10 @@ protected function handle(): int
3431 $ this ->warn ('Configuration file already exists ' );
3532 $ this ->warn ('If you continue your configuration will be overwritten ' );
3633
37- if ($ this ->ask ("\n Are you sure you want to continue? [Y/n] " , ' n ' ) !== ' Y ' ) {
34+ if (! $ this ->confirm ("\n Are you sure you want to continue? " ) ) {
3835 $ this ->info ("\n Alright! \n" );
39- return 1 ;
36+
37+ return self ::INVALID ;
4038 }
4139 }
4240
@@ -50,14 +48,12 @@ protected function handle(): int
5048 $ this ->askForGitHubRepository ();
5149 $ this ->saveConfig ();
5250
53- return 0 ;
51+ return self :: SUCCESS ;
5452 }
5553
56- protected function askForMantisUrl (): void
54+ private function askForMantisUrl (): void
5755 {
58- $ this ->info (" Please enter the URL of your Mantis installation (e.g. https://tickets.company.tld): " );
59-
60- $ mantisUrl = $ this ->ask (" > " );
56+ $ mantisUrl = $ this ->ask ('Please enter the URL of your Mantis installation (e.g. https://tickets.company.tld): ' );
6157
6258 $ parsedUrl = parse_url ($ mantisUrl );
6359
@@ -72,7 +68,7 @@ protected function askForMantisUrl(): void
7268 $ mantisUrl = "{$ parsedUrl ['scheme ' ]}:// {$ parsedUrl ['host ' ]}$ port/ " ;
7369
7470 // Check if something is available on the given URL
75- // If not, we assume that the URL is wrong
71+ // If not, we assume that the URL is wrong.
7672 $ headers = @get_headers ($ mantisUrl );
7773 if (!$ headers || $ headers [0 ] === 'HTTP/1.1 404 Not Found ' ) {
7874 $ this ->error (
@@ -85,12 +81,10 @@ protected function askForMantisUrl(): void
8581 $ this ->config ['mantisUrl ' ] = $ mantisUrl ;
8682 }
8783
88- protected function askForMantisToken (): void
84+ private function askForMantisToken (): void
8985 {
90- $ this ->info ("\n Head over to {$ this ->config ['mantisUrl ' ]}api_tokens_page.php, create a new API token, " );
91- $ this ->info (" and enter the token here: " );
92-
93- $ token = $ this ->secret (" > " );
86+ $ this ->info ("Head over to {$ this ->config ['mantisUrl ' ]}api_tokens_page.php and create a new API token. " );
87+ $ token = $ this ->secret ('Mantis API Token ' );
9488
9589 if (empty ($ token )) {
9690 $ this ->error ('The token is empty. Please try again. ' );
@@ -101,12 +95,11 @@ protected function askForMantisToken(): void
10195 $ this ->config ['mantisToken ' ] = $ token ;
10296 }
10397
104- protected function askForGitHubToken (): void
98+ private function askForGitHubToken (): void
10599 {
106- $ this ->info ("\n Head over to https://github.com/settings/tokens, create a new personal access token " );
107- $ this ->info (" with the `repo` scope and enter the token here: " );
100+ $ this ->info ("Head over to https://github.com/settings/tokens, create a new personal access token with the `repo` scope. " );
108101
109- $ token = $ this ->secret (" > " );
102+ $ token = $ this ->secret ("GitHub Token " );
110103
111104 if (empty ($ token )) {
112105 $ this ->error ('The token is empty. Please try again. ' );
@@ -117,11 +110,9 @@ protected function askForGitHubToken(): void
117110 $ this ->config ['githubToken ' ] = $ token ;
118111 }
119112
120- protected function askForGitHubRepository (): void
113+ private function askForGitHubRepository (): void
121114 {
122- $ this ->info ("\n Enter the GitHub repository you want to create issues for (e.g. user/repository): " );
123-
124- $ repository = $ this ->ask (" > " );
115+ $ repository = $ this ->ask ('Enter the GitHub repository you want to create issues for (e.g. user/repository) ' );
125116
126117 if (empty ($ repository ) || count (explode ('/ ' , $ repository )) !== 2 ) {
127118 $ this ->error ("The given repository is invalid. " );
@@ -132,7 +123,7 @@ protected function askForGitHubRepository(): void
132123 $ this ->config ['githubRepository ' ] = $ repository ;
133124 }
134125
135- protected function saveConfig (): void
126+ private function saveConfig (): void
136127 {
137128 $ stub = file_get_contents (__DIR__ . '/../../stubs/config.yaml.stub ' );
138129
@@ -153,7 +144,7 @@ protected function saveConfig(): void
153144 $ this ->success (" Synchronize your first issue by running `mantis2github sync`! \n" );
154145 }
155146
156- protected function readExistingConfigFromPath ()
147+ private function readExistingConfigFromPath (): void
157148 {
158149 if (!$ this ->argument ('file ' )) {
159150 return ;
@@ -183,6 +174,6 @@ protected function readExistingConfigFromPath()
183174
184175 $ this ->saveConfig ();
185176
186- exit (0 );
177+ exit (self :: SUCCESS );
187178 }
188179}
0 commit comments