@@ -41,11 +41,26 @@ class PharController extends Controller
4141 */
4242 private $ compilerConfiger ;
4343
44- protected function init (): void
44+ /**
45+ * @var string
46+ */
47+ private $ defPkgName ;
48+
49+ protected static function commandAliases (): array
50+ {
51+ return [
52+ 'pack ' => ['build ' ]
53+ ];
54+ }
55+
56+ /**
57+ * @param Input $input
58+ */
59+ protected function packConfigure (Input $ input ): void
4560 {
46- parent :: init () ;
61+ $ this -> defPkgName = trim ( basename ( $ input -> getPwd ()), ' . ' ) . PharCompiler:: FILE_EXT ;
4762
48- $ this ->addCommentsVar ('defaultPkgName ' , basename ( $ this ->input -> getPwd ()) );
63+ $ this ->addCommentsVar ('defaultPkgName ' , $ this ->defPkgName );
4964 }
5065
5166 /**
@@ -54,9 +69,9 @@ protected function init(): void
5469 *
5570 * @options
5671 * -d, --dir STRING Setting the project directory for packing.
57- * default is current work-dir.( <cyan>{workDir}</cyan>)
58- * -c, --config STRING Use the custom config file for build phar(<cyan>./phar.build.inc</cyan>)
59- * -o, --output STRING Setting the output file name(<cyan>{defaultPkgName}.phar </cyan>)
72+ * default is current work-dir(default: <cyan>{workDir}</cyan>)
73+ * -c, --config STRING Use the custom config file for build phar(default: <cyan>./phar.build.inc</cyan>)
74+ * -o, --output STRING Setting the output file name(<cyan>{defaultPkgName}</cyan>)
6075 * --fast Fast build. only add modified files by <cyan>git status -s</cyan>
6176 * --refresh Whether build vendor folder files on phar file exists(<cyan>False</cyan>)
6277 * --files STRING Only pack the list files to the exist phar, multi use ',' split
@@ -68,25 +83,25 @@ protected function init(): void
6883 * @return int
6984 * @throws Exception
7085 * @example
71- * {fullCommand} Pack current dir to a phar file.
72- * {fullCommand} --dir vendor/swoft/devtool Pack the specified dir to a phar file.
86+ * {fullCommand} Pack current dir to a phar file.
87+ * {fullCommand} --dir vendor/swoft/devtool Pack the specified dir to a phar file.
7388 *
74- * custom output phar file name
89+ * custom output phar file name
7590 * php -d phar.readonly=0 {binFile} phar:pack -o=mycli.phar
7691 *
77- * only update the input files:
92+ * only update the input files:
7893 * php -d phar.readonly=0 {binFile} phar:pack -o=mycli.phar --debug --files app/Command/ServeCommand.php
7994 */
8095 public function packCommand ($ input , $ output ): int
8196 {
82- $ startAt = microtime (1 );
97+ $ startAt = microtime (true );
8398 $ workDir = $ input ->getPwd ();
8499
85100 $ dir = $ input ->getOpt ('dir ' ) ?: $ workDir ;
86101 $ cpr = $ this ->configCompiler ($ dir );
87102
88103 $ refresh = $ input ->boolOpt ('refresh ' );
89- $ outFile = $ input ->sameOpt (['o ' , 'output ' ], basename ( $ workDir ) . ' .phar ' );
104+ $ outFile = $ input ->getSameStringOpt (['o ' , 'output ' ], $ this -> defPkgName );
90105 $ pharFile = $ workDir . '/ ' . $ outFile ;
91106
92107 Show::aList ([
@@ -186,7 +201,7 @@ private function outputProgress(PharCompiler $cpr,Input $input): void
186201 });
187202 } else {
188203 $ counter = Show::counterTxt ('Collecting ... ' , 'Done. ' );
189- $ cpr ->onAdd (function () use ($ counter ) {
204+ $ cpr ->onAdd (static function () use ($ counter ) {
190205 $ counter ->send (1 );
191206 });
192207 $ cpr ->on (PharCompiler::ON_COLLECTED , function () use ($ counter ) {
0 commit comments