3
3
namespace Juzaweb \AutoDeploy \Commands ;
4
4
5
5
use Illuminate \Console \Command ;
6
- use Illuminate \ Support \ Facades \ Log ;
6
+ use Juzaweb \ AutoDeploy \ Contrasts \ AutoDeploy ;
7
7
use Symfony \Component \Console \Input \InputArgument ;
8
- use Symfony \Component \Process \Process ;
9
- use Noodlehaus \Config ;
10
8
11
9
class AutoDeployCommand extends Command
12
10
{
11
+ public function __construct (protected AutoDeploy $ autoDeploy )
12
+ {
13
+ parent ::__construct ();
14
+ }
15
+
13
16
/**
14
17
* The console command name.
15
18
*
@@ -32,59 +35,17 @@ class AutoDeployCommand extends Command
32
35
public function handle (): int
33
36
{
34
37
$ action = $ this ->argument ('action ' );
35
- if (config ('deploy.method ' ) == 'cron ' ) {
36
- $ schedule = get_config ('deploy_schedules ' , []);
37
- if (empty ($ schedule )) {
38
- return self ::SUCCESS ;
39
- }
40
-
41
- $ action = array_key_first ($ schedule );
42
- unset($ schedule [$ action ]);
43
- set_config ('deploy_schedules ' , $ schedule );
44
-
45
- $ this ->runAction ($ action );
46
- return self ::SUCCESS ;
47
- }
48
-
49
- $ this ->runAction ($ action );
50
-
51
- return self ::SUCCESS ;
52
- }
53
-
54
- protected function runAction (string $ action ): int
55
- {
56
- $ config = Config::load (base_path ('.deploy.yml ' ));
57
- $ commands = $ config ->get ("{$ action }.commands " , []);
58
- if (empty ($ commands )) {
59
- $ this ->error ("Action not found. " );
60
- return self ::SUCCESS ;
61
- }
62
-
63
- foreach ($ commands as $ command ) {
64
- $ this ->info ("Running ' {$ command }' " );
65
- $ cmd = explode (' ' , trim ($ command ));
66
- if ($ cmd [0 ] == 'php ' && $ cmd [1 ] == 'artisan ' ) {
67
- $ this ->call ($ cmd [2 ]);
68
- } else {
69
- $ process = new Process ($ cmd );
70
-
71
- $ process ->run (
72
- function ($ type , $ buffer ) {
73
- $ this ->info ($ buffer );
74
- }
75
- );
76
- }
77
- }
78
-
79
- Log::info ("Deploy success {$ action }" );
80
-
38
+
39
+ $ this ->autoDeploy ->run ($ action );
40
+
81
41
return self ::SUCCESS ;
82
42
}
83
-
43
+
84
44
protected function getArguments (): array
85
45
{
86
46
return [
87
- ['action ' , InputArgument::OPTIONAL , 'The action to run. ' ],
47
+ ['action ' , InputArgument::REQUIRED , 'The action to run. ' ],
48
+ ['token ' , InputArgument::REQUIRED , 'The token to run. ' ],
88
49
];
89
50
}
90
51
}
0 commit comments