17
17
use Inhere \Console \Util \Helper ;
18
18
use Inhere \Console \Util \Show ;
19
19
use RuntimeException ;
20
+ use Toolkit \PFlag \FlagsParser ;
20
21
use Toolkit \Stdlib \Str ;
21
22
use function basename ;
22
23
use function file_exists ;
@@ -77,8 +78,9 @@ protected function packConfigure(Input $input): void
77
78
* --files Only pack the list files to the exist phar, multi use ',' split
78
79
* --no-progress bool;Disable output progress on the runtime
79
80
*
80
- * @param Input $input
81
+ * @param Input $input
81
82
* @param Output $output
83
+ * @param FlagsParser $fs
82
84
*
83
85
* @return int
84
86
* @throws Exception
@@ -92,16 +94,16 @@ protected function packConfigure(Input $input): void
92
94
* only update the input files:
93
95
* php -d phar.readonly=0 {binFile} phar:pack -o=mycli.phar --debug --files app/Command/ServeCommand.php
94
96
*/
95
- public function packCommand (Input $ input , Output $ output ): int
97
+ public function packCommand (Input $ input , Output $ output, FlagsParser $ fs ): int
96
98
{
97
99
$ startAt = microtime (true );
98
100
$ workDir = $ input ->getPwd ();
99
101
100
- $ dir = $ input ->getOpt ('dir ' ) ?: $ workDir ;
102
+ $ dir = $ fs ->getOpt ('dir ' ) ?: $ workDir ;
101
103
$ cpr = $ this ->configCompiler ($ dir );
102
104
103
- $ refresh = $ input -> boolOpt ('refresh ' );
104
- $ outFile = $ input -> getSameStringOpt ([ ' o ' , ' output '] , $ this ->defPkgName );
105
+ $ refresh = $ fs -> getOpt ('refresh ' );
106
+ $ outFile = $ fs -> getOpt ( ' output ' , $ this ->defPkgName );
105
107
$ pharFile = $ workDir . '/ ' . $ outFile ;
106
108
107
109
Show::aList ([
@@ -111,13 +113,13 @@ public function packCommand(Input $input, Output $output): int
111
113
], 'Building Information ' );
112
114
113
115
// use fast build
114
- if ($ this -> input -> boolOpt ('fast ' )) {
116
+ if ($ fs -> getOpt ('fast ' )) {
115
117
$ cpr ->setModifies ($ cpr ->findChangedByGit ());
116
118
$ this ->output ->liteNote ('Use fast build, will only pack changed or new files(from git status) ' );
117
119
}
118
120
119
121
// Manual append some files
120
- if ($ files = $ input -> getStringOpt ('files ' )) {
122
+ if ($ files = $ fs -> getOpt ('files ' )) {
121
123
$ cpr ->setModifies (Str::explode ($ files ));
122
124
$ output ->liteInfo ("will only pack input files to the exists phar: $ outFile " );
123
125
}
@@ -130,7 +132,10 @@ public function packCommand(Input $input, Output $output): int
130
132
});
131
133
132
134
$ output ->colored ('Collect Pack files ' , 'comment ' );
133
- $ this ->outputProgress ($ cpr , $ input );
135
+
136
+ if (!$ fs ->getOpt ('no-progress ' )) {
137
+ $ this ->outputProgress ($ cpr );
138
+ }
134
139
135
140
// packing ...
136
141
$ cpr ->pack ($ pharFile , $ refresh );
@@ -178,17 +183,12 @@ protected function configCompiler(string $dir): PharCompiler
178
183
179
184
/**
180
185
* @param PharCompiler $cpr
181
- * @param Input $input
182
186
*
183
187
* @return void
184
188
*/
185
- private function outputProgress (PharCompiler $ cpr, Input $ input ): void
189
+ private function outputProgress (PharCompiler $ cpr ): void
186
190
{
187
- if ($ input ->getBoolOpt ('no-progress ' )) {
188
- return ;
189
- }
190
-
191
- if ($ input ->getOpt ('debug ' )) {
191
+ if ($ this ->isDebug ()) {
192
192
// $output->info('Pack file to Phar ... ...');
193
193
$ cpr ->onAdd (function (string $ path ) {
194
194
$ this ->writeln (" <info>+</info> $ path " );
@@ -228,15 +228,16 @@ public function setCompilerConfiger(Closure $compilerConfiger): void
228
228
* -y, --yes bool;Whether display goon tips message.
229
229
* --overwrite bool;Whether overwrite exists files on extract phar
230
230
*
231
- * @param Input $in
231
+ * @param Input $in
232
232
* @param Output $out
233
+ * @param FlagsParser $fs
233
234
*
234
235
* @return int
235
236
* @example {fullCommand} -f myapp.phar -d var/www/app
236
237
*/
237
- public function unpackCommand ($ in , $ out ): int
238
+ public function unpackCommand (Input $ in , Output $ out, FlagsParser $ fs ): int
238
239
{
239
- if (!$ path = $ in -> getSameOpt ([ ' f ' , ' file '] )) {
240
+ if (!$ path = $ fs -> getOpt ( ' file ' )) {
240
241
return $ out ->error ("Please input the phar file path by option '-f|--file' " );
241
242
}
242
243
@@ -247,8 +248,8 @@ public function unpackCommand($in, $out): int
247
248
return $ out ->error ("The phar file not exists. File: $ file " );
248
249
}
249
250
250
- $ dir = $ in -> getSameOpt ([ ' d ' , ' dir '] ) ?: $ basePath ;
251
- $ overwrite = $ in -> getBoolOpt ('overwrite ' );
251
+ $ dir = $ fs -> getOpt ( ' dir ' ) ?: $ basePath ;
252
+ $ overwrite = $ fs -> getOpt ('overwrite ' );
252
253
253
254
if (!is_dir ($ dir )) {
254
255
Helper::mkdir ($ dir );
0 commit comments