1
+ <?php declare (strict_types=1 );
2
+
3
+ namespace Bref \Cli \Commands ;
4
+
5
+ use Bref \Cli \BrefCloudClient ;
6
+ use Bref \Cli \Cli \IO ;
7
+ use Bref \Cli \Cli \OpenUrl ;
8
+ use Bref \Cli \Cli \Styles ;
9
+ use Bref \Cli \Config ;
10
+ use JsonException ;
11
+ use Symfony \Component \Console \Input \InputArgument ;
12
+ use Symfony \Component \Console \Input \InputInterface ;
13
+ use Symfony \Component \Console \Input \InputOption ;
14
+ use Symfony \Component \Console \Output \OutputInterface ;
15
+
16
+ class Cloud extends \Symfony \Component \Console \Command \Command
17
+ {
18
+ protected function configure (): void
19
+ {
20
+ $ this
21
+ ->setName ('cloud ' )
22
+ ->setDescription ('Open the Bref Cloud dashboard ' )
23
+ ->addOption ('config ' , 'c ' , InputOption::VALUE_REQUIRED , 'The location of the configuration file to use ' )
24
+ ->addOption ('env ' , 'e ' , InputOption::VALUE_REQUIRED , 'The environment ' , 'dev ' );
25
+ }
26
+
27
+ protected function execute (InputInterface $ input , OutputInterface $ output ): int
28
+ {
29
+ /** @var string|null $configFileName */
30
+ $ configFileName = $ input ->getOption ('config ' );
31
+ /** @var string $environment */
32
+ $ environment = $ input ->getOption ('env ' );
33
+
34
+ $ config = Config::loadConfig ($ configFileName , $ environment , null );
35
+ $ appName = $ config ['name ' ];
36
+ $ teamSlug = $ config ['team ' ];
37
+
38
+ $ brefCloud = new BrefCloudClient ;
39
+ $ environment = $ brefCloud ->getEnvironment ($ teamSlug , $ appName , $ environment );
40
+
41
+ $ url = $ brefCloud ->url . '/environment/ ' . $ environment ['id ' ];
42
+
43
+ IO ::writeln ([Styles::brefHeader (), '' ]);
44
+ IO ::writeln ([
45
+ 'Opening the Bref Cloud dashboard for the environment ' ,
46
+ Styles::gray (Styles::underline ($ url )),
47
+ '' ,
48
+ ]);
49
+
50
+ OpenUrl::open ($ url );
51
+
52
+ return 0 ;
53
+ }
54
+ }
0 commit comments