2
2
3
3
namespace ArtARTs36 \MergeRequestLinter \Console \Command ;
4
4
5
- use Symfony \Component \Console \Command \Command ;
5
+ use ArtARTs36 \MergeRequestLinter \Configuration \ConfigFormat ;
6
+ use ArtARTs36 \MergeRequestLinter \Configuration \Copier ;
7
+ use ArtARTs36 \MergeRequestLinter \Support \File \Directory ;
6
8
use Symfony \Component \Console \Input \InputInterface ;
9
+ use Symfony \Component \Console \Input \InputOption ;
7
10
use Symfony \Component \Console \Output \OutputInterface ;
8
11
use Symfony \Component \Console \Style \SymfonyStyle ;
9
12
@@ -13,21 +16,39 @@ class InstallCommand extends Command
13
16
14
17
protected static $ defaultDescription = 'Install this tool ' ;
15
18
16
- public function __construct (string $ name = null )
19
+ public function __construct (
20
+ private readonly Copier $ configCopier ,
21
+ ) {
22
+ parent ::__construct ();
23
+ }
24
+
25
+ protected function configure (): void
17
26
{
18
- parent ::__construct ($ name );
27
+ $ this
28
+ ->getDefinition ()
29
+ ->addOption (new InputOption ('format ' , mode: InputOption::VALUE_OPTIONAL ));
19
30
}
20
31
21
32
protected function execute (InputInterface $ input , OutputInterface $ output )
22
33
{
23
- $ dir = getcwd ( );
34
+ $ style = new SymfonyStyle ( $ input , $ output );
24
35
25
- copy (__DIR__ . '/../../../stubs/.mr-linter.php ' , $ pathTo = $ dir . '/.mr-linter.php ' );
36
+ $ dir = $ this ->getWorkDir ($ input );
37
+ $ format = $ this ->resolveConfigFormat ($ input );
26
38
27
- $ style = new SymfonyStyle ( $ input , $ output );
39
+ $ createdFile = $ this -> configCopier -> copy ( $ format , new Directory ( $ dir ) );
28
40
29
- $ style ->info ('Was copied configuration file to: ' . $ pathTo );
41
+ $ style ->info (sprintf ( 'Was copied configuration file to: %s [%s] ' , $ createdFile , $ createdFile -> getSizeString ()) );
30
42
31
43
return self ::SUCCESS ;
32
44
}
45
+
46
+ private function resolveConfigFormat (InputInterface $ input ): ConfigFormat
47
+ {
48
+ if ($ input ->getOption ('format ' ) !== null ) {
49
+ return ConfigFormat::from ($ input ->getOption ('format ' ));
50
+ }
51
+
52
+ return ConfigFormat::PHP ;
53
+ }
33
54
}
0 commit comments