php根據(jù)命令行參數(shù)生成配置文件

發(fā)布時間:2024-03-18
像npm, composer等工具,在開始使用的使用,都需要初始化項目,生成一個項目的配置文件。這種功能的原理是怎么實現(xiàn)的呢?
比如:
d:\>npm init --yes wrote to d:\package.json: { name: , version: 1.0.0, description: , main: index.js, directories: { doc: doc }, scripts: { test: echo \error: no test specified\ && exit 1 }, keywords: [], author: , license: isc其實很簡單,在之前這篇文章php解釋命令行的參數(shù)的基礎(chǔ)上,加上下面的init分支,即可實現(xiàn)類似的功能
#!/usr/bin/php <?php function init(){ return file_put_contents( getcwd() . '/go.json', '{}' ) . 'bytes has written.' . 'config file has created'; } $res = ''; if( $argc >= 2 ) { $argv[1] == '-v' && $res = 'go version is 1.0'; $argv[1] == 'init' && $res = init(); } echo $res . php_eol;ghostwu@ghostwu:~/mybin$ ls go2 ghostwu@ghostwu:~/mybin$ go2 init 2bytes has written.config file has created ghostwu@ghostwu:~/mybin$ ls go2 go.json ghostwu@ghostwu:~/mybin$ cat go.json {}ghostwu@ghostwu:~/mybin$
上一個:如何用硬盤給電腦裝系統(tǒng),怎么用硬盤安裝windows
下一個:華安縣鐵觀音生態(tài)茶園建設(shè)技術(shù)要點

鼎寶六光源對色燈箱的使用要點
離婚后還是有人過來要債怎么辦
編碼器在機(jī)器人產(chǎn)業(yè)中的應(yīng)用前景如何?
華為p8高配版待機(jī)時間怎么樣,華為p8用著怎么樣續(xù)航怎么樣性能怎么樣
厚聲1206W3F100MT5E今日行情、最新報價
筆記本電腦裝固態(tài)硬盤教程圖
信偉慧誠COD總氮總磷等水樣的消解預(yù)處理配套快速消解儀
玻璃幕墻安裝工程施工質(zhì)量技術(shù)要求有哪些?
德國賀德克hydac污染傳感器cs 1000
三款茶美食讓你停不下來
十八禁 网站在线观看免费视频_2020av天堂网_一 级 黄 色 片免费网站_绝顶高潮合集Videos